| 15 | using namespace boost::filesystem; |
| 16 | |
| 17 | int main(int argc, char* argv[]) |
| 18 | { |
| 19 | if (argc < 2) |
| 20 | { |
| 21 | cout << "Usage: tut3 path\n"; |
| 22 | return 1; |
| 23 | } |
| 24 | |
| 25 | path p (argv[1]); // p reads clearer than argv[1] in the following code |
| 26 | |
| 27 | try |
| 28 | { |
| 29 | if (exists(p)) // does p actually exist? |
| 30 | { |
| 31 | if (is_regular_file(p)) // is p a regular file? |
| 32 | cout << p << " size is " << file_size(p) << '\n'; |
| 33 | |
| 34 | else if (is_directory(p)) // is p a directory? |
| 35 | { |
| 36 | cout << p << " is a directory containing:\n"; |
| 37 | |
| 38 | copy(directory_iterator(p), directory_iterator(), // directory_iterator::value_type |
| 39 | ostream_iterator<directory_entry>(cout, "\n")); // is directory_entry, which is |
| 40 | // converted to a path by the |
| 41 | // path stream inserter |
| 42 | } |
| 43 | else |
| 44 | cout << p << " exists, but is neither a regular file nor a directory\n"; |
| 45 | } |
| 46 | else |
| 47 | cout << p << " does not exist\n"; |
| 48 | } |
| 49 | |
| 50 | catch (const filesystem_error& ex) |
| 51 | { |
| 52 | cout << ex.what() << '\n'; |
| 53 | } |
| 54 | |
| 55 | return 0; |
| 56 | } |
nothing calls this directly
no test coverage detected