MCPcopy Create free account
hub / github.com/davisking/dlib / main

Function main

examples/dir_nav_ex.cpp:21–73  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19
20
21int main(int argc, char** argv)
22{
23 try
24 {
25 string loc;
26 if (argc == 2)
27 loc = argv[1];
28 else
29 loc = "."; // if no argument is given then use the current working dir.
30
31 directory test(loc);
32
33
34 cout << "directory: " << test.name() << endl;
35 cout << "full path: " << test.full_name() << endl;
36 cout << "is root: " << ((test.is_root())?"yes":"no") << endl;
37
38 // get all directories and files in test
39 std::vector<directory> dirs = test.get_dirs();
40 std::vector<file> files = test.get_files();
41
42 // sort the files and directories
43 sort(files.begin(), files.end());
44 sort(dirs.begin(), dirs.end());
45
46 cout << "\n\n\n";
47
48 // print all the subdirectories
49 for (unsigned long i = 0; i < dirs.size(); ++i)
50 cout << " <DIR> " << dirs[i].name() << "\n";
51
52 // print all the subfiles
53 for (unsigned long i = 0; i < files.size(); ++i)
54 cout << setw(13) << files[i].size() << " " << files[i].name() << "\n";
55
56
57 cout << "\n\nnumber of dirs: " << dirs.size() << endl;
58 cout << "number of files: " << files.size() << endl;
59
60 }
61 catch (file::file_not_found& e)
62 {
63 cout << "file not found or accessible: " << e.info << endl;
64 }
65 catch (directory::dir_not_found& e)
66 {
67 cout << "dir not found or accessible: " << e.info << endl;
68 }
69 catch (directory::listing_error& e)
70 {
71 cout << "listing error: " << e.info << endl;
72 }
73}
74
75

Callers

nothing calls this directly

Calls 7

nameMethod · 0.45
is_rootMethod · 0.45
get_dirsMethod · 0.45
get_filesMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected