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

Function main

example/simple_ls.cpp:26–90  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 9

statusMethod · 0.80
filenameMethod · 0.80
pathMethod · 0.80
whatMethod · 0.80
current_pathFunction · 0.50
system_completeFunction · 0.50
existsFunction · 0.50
is_directoryFunction · 0.50
is_regular_fileFunction · 0.50

Tested by

no test coverage detected