1 // status.cpp ------------------------------------------------------------------------//
3 // Copyright Beman Dawes 2011
5 // Distributed under the Boost Software License, Version 1.0.
6 // See http://www.boost.org/LICENSE_1_0.txt
8 // Library home page: http://www.boost.org/libs/filesystem
11 #include <boost/config.hpp>
12 #include <boost/version.hpp>
13 #include <boost/filesystem.hpp>
14 #include <boost/detail/lightweight_main.hpp>
16 using std::cout; using std::endl;
17 using namespace boost::filesystem;
23 void print_boost_macros()
26 << BOOST_VERSION / 100000 << '.'
27 << BOOST_VERSION / 100 % 1000 << '.'
28 << BOOST_VERSION % 100 << ", "
30 << BOOST_COMPILER << ", "
32 << BOOST_COMPILER << " with _WIN64 defined, "
34 << BOOST_STDLIB << ", "
39 const char* file_type_tab[] =
40 { "status_error", "file_not_found", "regular_file", "directory_file",
41 "symlink_file", "block_file", "character_file", "fifo_file", "socket_file",
45 const char* file_type_c_str(enum file_type t)
47 return file_type_tab[t];
50 void show_status(file_status s, boost::system::error_code ec)
52 boost::system::error_condition econd;
56 econd = ec.default_error_condition();
57 cout << "sets ec to indicate an error:\n"
58 << " ec.value() is " << ec.value() << '\n'
59 << " ec.message() is \"" << ec.message() << "\"\n"
60 << " ec.default_error_condition().value() is " << econd.value() << '\n'
61 << " ec.default_error_condition().message() is \"" << econd.message() << "\"\n";
64 cout << "clears ec.\n";
66 cout << "s.type() is " << s.type()
67 << ", which is defined as \"" << file_type_c_str(s.type()) << "\"\n";
69 cout << "exists(s) is " << (exists(s) ? "true" : "false") << "\n";
70 cout << "status_known(s) is " << (status_known(s) ? "true" : "false") << "\n";
71 cout << "is_regular_file(s) is " << (is_regular_file(s) ? "true" : "false") << "\n";
72 cout << "is_directory(s) is " << (is_directory(s) ? "true" : "false") << "\n";
73 cout << "is_other(s) is " << (is_other(s) ? "true" : "false") << "\n";
74 cout << "is_symlink(s) is " << (is_symlink(s) ? "true" : "false") << "\n";
79 cout << "\nexists(" << p << ") ";
82 bool result = exists(p);
83 cout << "is " << (result ? "true" : "false") << "\n";
85 catch (const filesystem_error& ex)
87 cout << "throws a filesystem_error exception: " << ex.what() << "\n";
93 int cpp_main(int argc, char* argv[])
99 std::cout << "Usage: file_status <path>\n";
105 boost::system::error_code ec;
106 file_status s = status(p, ec);
107 cout << "\nfile_status s = status(" << p << ", ec) ";
110 s = symlink_status(p, ec);
111 cout << "\nfile_status s = symlink_status(" << p << ", ec) ";