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

Function main

example/tut4.cpp:18–65  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16using namespace boost::filesystem;
17
18int 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]); // p reads clearer than argv[1] in the following code
27
28 try
29 {
30 if (exists(p)) // does p actually exist?
31 {
32 if (is_regular_file(p)) // is p a regular file?
33 cout << p << " size is " << file_size(p) << '\n';
34
35 else if (is_directory(p)) // is p a directory?
36 {
37 cout << p << " is a directory containing:\n";
38
39 typedef vector<path> vec; // store paths,
40 vec v; // so we can sort them later
41
42 copy(directory_iterator(p), directory_iterator(), back_inserter(v));
43
44 sort(v.begin(), v.end()); // sort, since directory iteration
45 // is not ordered on some file systems
46
47 for (vec::const_iterator it(v.begin()), it_end(v.end()); it != it_end; ++it)
48 {
49 cout << " " << *it << '\n';
50 }
51 }
52 else
53 cout << p << " exists, but is neither a regular file nor a directory\n";
54 }
55 else
56 cout << p << " does not exist\n";
57 }
58
59 catch (const filesystem_error& ex)
60 {
61 cout << ex.what() << '\n';
62 }
63
64 return 0;
65}

Callers

nothing calls this directly

Calls 8

existsFunction · 0.85
is_regular_fileFunction · 0.85
file_sizeFunction · 0.85
is_directoryFunction · 0.85
directory_iteratorClass · 0.85
beginMethod · 0.80
endMethod · 0.80
copyFunction · 0.50

Tested by

no test coverage detected