| 1 | #include <iostream>
|
|---|
| 2 | #include <boost/filesystem.hpp>
|
|---|
| 3 |
|
|---|
| 4 | using namespace std;
|
|---|
| 5 | using namespace boost::filesystem;
|
|---|
| 6 |
|
|---|
| 7 | static string gvGetFileType(const file_type avFileType)
|
|---|
| 8 | {
|
|---|
| 9 | switch (avFileType)
|
|---|
| 10 | {
|
|---|
| 11 | case status_unknown:
|
|---|
| 12 | return "status unknown";
|
|---|
| 13 | case file_not_found:
|
|---|
| 14 | return "file not found";
|
|---|
| 15 | case regular_file:
|
|---|
| 16 | return "regular file";
|
|---|
| 17 | case directory_file:
|
|---|
| 18 | return "directory file";
|
|---|
| 19 | case symlink_file:
|
|---|
| 20 | return "symbolic link file";
|
|---|
| 21 | case block_file:
|
|---|
| 22 | return "block special file";
|
|---|
| 23 | case character_file:
|
|---|
| 24 | return "character special file";
|
|---|
| 25 | case fifo_file:
|
|---|
| 26 | return "fifo file";
|
|---|
| 27 | case socket_file:
|
|---|
| 28 | return "socket file";
|
|---|
| 29 | case type_unknown:
|
|---|
| 30 | default:
|
|---|
| 31 | return "type unknown";
|
|---|
| 32 | }
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 | static void gvDisplayDirEntry(const char* apDescription, const char* apPath)
|
|---|
| 36 | {
|
|---|
| 37 | path vPath(apPath);
|
|---|
| 38 | directory_entry vDirEntry(vPath.make_preferred());
|
|---|
| 39 |
|
|---|
| 40 | cout
|
|---|
| 41 | << apDescription << ":" << endl
|
|---|
| 42 | << endl
|
|---|
| 43 | << " " << vDirEntry.path().native()
|
|---|
| 44 | << " status is " << gvGetFileType(vDirEntry.status().type()) << endl
|
|---|
| 45 | << endl;
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 | int main(int /*argc*/, char* argv[])
|
|---|
| 49 | {
|
|---|
| 50 | gvDisplayDirEntry("An unknown path", "dummy");
|
|---|
| 51 | gvDisplayDirEntry("A file path", argv[0]);
|
|---|
| 52 | gvDisplayDirEntry("A directory path", current_path().string().c_str());
|
|---|
| 53 |
|
|---|
| 54 | return 0;
|
|---|
| 55 | }
|
|---|