| 16 | using namespace boost::filesystem; |
| 17 | |
| 18 | int main(int argc, char* argv[]) |
| 19 | { |
| 20 | if (argc < 2) |
| 21 | { |
| 22 | cout << "Usage: tut4 path\n"; |
| 23 | return 1; |
| 24 | } |
| 25 | |
| 26 | path p(argv[1]); |
| 27 | |
| 28 | try |
| 29 | { |
| 30 | if (exists(p)) |
| 31 | { |
| 32 | if (is_regular_file(p)) |
| 33 | { |
| 34 | cout << p << " size is " << file_size(p) << '\n'; |
| 35 | } |
| 36 | else if (is_directory(p)) |
| 37 | { |
| 38 | cout << p << " is a directory containing:\n"; |
| 39 | |
| 40 | std::vector< path > v; |
| 41 | |
| 42 | for (auto&& x : directory_iterator(p)) |
| 43 | v.push_back(x.path()); |
| 44 | |
| 45 | std::sort(v.begin(), v.end()); |
| 46 | |
| 47 | for (auto&& x : v) |
| 48 | cout << " " << x.filename() << '\n'; |
| 49 | } |
| 50 | else |
| 51 | cout << p << " exists, but is not a regular file or directory\n"; |
| 52 | } |
| 53 | else |
| 54 | cout << p << " does not exist\n"; |
| 55 | } |
| 56 | catch (filesystem_error& ex) |
| 57 | { |
| 58 | cout << ex.what() << '\n'; |
| 59 | } |
| 60 | |
| 61 | return 0; |
| 62 | } |
nothing calls this directly
no test coverage detected