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

Function main

example/simple_ls.cpp:28–91  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26namespace fs = boost::filesystem;
27
28int main(int argc, char* argv[])
29{
30 fs::path p(fs::current_path());
31
32 if (argc > 1)
33 p = fs::system_complete(argv[1]);
34 else
35 std::cout << "\nusage: simple_ls [path]" << std::endl;
36
37 unsigned long file_count = 0;
38 unsigned long dir_count = 0;
39 unsigned long other_count = 0;
40 unsigned long err_count = 0;
41
42 if (!fs::exists(p))
43 {
44 std::cout << "\nNot found: " << p << std::endl;
45 return 1;
46 }
47
48 if (fs::is_directory(p))
49 {
50 std::cout << "\nIn directory: " << p << "\n\n";
51 fs::directory_iterator end_iter;
52 for (fs::directory_iterator dir_itr(p);
53 dir_itr != end_iter;
54 ++dir_itr)
55 {
56 try
57 {
58 if (fs::is_directory(dir_itr->status()))
59 {
60 ++dir_count;
61 std::cout << dir_itr->path().filename() << " [directory]\n";
62 }
63 else if (fs::is_regular_file(dir_itr->status()))
64 {
65 ++file_count;
66 std::cout << dir_itr->path().filename() << "\n";
67 }
68 else
69 {
70 ++other_count;
71 std::cout << dir_itr->path().filename() << " [other]\n";
72 }
73
74 }
75 catch (const std::exception & ex)
76 {
77 ++err_count;
78 std::cout << dir_itr->path().filename() << " " << ex.what() << std::endl;
79 }
80 }
81 std::cout << "\n" << file_count << " files\n"
82 << dir_count << " directories\n"
83 << other_count << " others\n"
84 << err_count << " errors\n";
85 }

Callers

nothing calls this directly

Calls 7

existsFunction · 0.85
is_directoryFunction · 0.85
is_regular_fileFunction · 0.85
statusMethod · 0.80
filenameMethod · 0.80
current_pathFunction · 0.50
system_completeFunction · 0.50

Tested by

no test coverage detected