MCPcopy Create free account
hub / github.com/boostorg/filesystem / main

Function main

example/tut3.cpp:17–56  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15using namespace boost::filesystem;
16
17int 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}

Callers

nothing calls this directly

Calls 6

existsFunction · 0.85
is_regular_fileFunction · 0.85
file_sizeFunction · 0.85
is_directoryFunction · 0.85
directory_iteratorClass · 0.85
copyFunction · 0.50

Tested by

no test coverage detected