#include <iostream>
#include <glibmm.h>
#include <giomm.h>
bool scan_directory(std::string path) {
try {
Glib::RefPtr<Gio::File> directory =
Gio::File::create_for_path(path);
Glib::RefPtr<Gio::FileEnumerator> enumerator =
directory->enumerate_children();
Glib::RefPtr<Gio::FileInfo> file_info;
while (file_info = enumerator->next_file()) {
if (file_info->get_file_type() == Gio::FILE_TYPE_DIRECTORY)
scan_directory(path + file_info->get_name() +
G_DIR_SEPARATOR_S);
else {
//do some staff, for example:
std::cout << path + file_info->get_name() << "\t" <<
file_info->get_content_type() << std::endl;
}
}
enumerator->close(); //seems to be not necessary
return true;
}
catch(const Glib::Exception& ex) {
std::cerr << "Error: " << ex.what() << std::endl;
return false;
}
}
int main(int argc, char** argv) {
setlocale(LC_ALL, "");
Glib::init();
Gio::init();
scan_directory((argc == 2) ? argv[1] : "");
return 0;
}