|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <iostream> |
|
#include <iomanip> |
|
#include <dlib/dir_nav.h> |
|
#include <vector> |
|
#include <algorithm> |
|
|
|
using namespace std; |
|
using namespace dlib; |
|
|
|
|
|
int main(int argc, char** argv) |
|
{ |
|
try |
|
{ |
|
string loc; |
|
if (argc == 2) |
|
loc = argv[1]; |
|
else |
|
loc = "."; |
|
|
|
directory test(loc); |
|
|
|
|
|
cout << "directory: " << test.name() << endl; |
|
cout << "full path: " << test.full_name() << endl; |
|
cout << "is root: " << ((test.is_root())?"yes":"no") << endl; |
|
|
|
|
|
std::vector<directory> dirs = test.get_dirs(); |
|
std::vector<file> files = test.get_files(); |
|
|
|
|
|
sort(files.begin(), files.end()); |
|
sort(dirs.begin(), dirs.end()); |
|
|
|
cout << "\n\n\n"; |
|
|
|
|
|
for (unsigned long i = 0; i < dirs.size(); ++i) |
|
cout << " <DIR> " << dirs[i].name() << "\n"; |
|
|
|
|
|
for (unsigned long i = 0; i < files.size(); ++i) |
|
cout << setw(13) << files[i].size() << " " << files[i].name() << "\n"; |
|
|
|
|
|
cout << "\n\nnumber of dirs: " << dirs.size() << endl; |
|
cout << "number of files: " << files.size() << endl; |
|
|
|
} |
|
catch (file::file_not_found& e) |
|
{ |
|
cout << "file not found or accessible: " << e.info << endl; |
|
} |
|
catch (directory::dir_not_found& e) |
|
{ |
|
cout << "dir not found or accessible: " << e.info << endl; |
|
} |
|
catch (directory::listing_error& e) |
|
{ |
|
cout << "listing error: " << e.info << endl; |
|
} |
|
} |
|
|
|
|
|
|