path_info.cpp 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // path_info.cpp ---------------------------------------------------------------------//
  2. // Copyright Beman Dawes 2009
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // See http://www.boost.org/LICENSE_1_0.txt
  5. // Library home page: http://www.boost.org/libs/filesystem
  6. #include <iostream>
  7. #include <boost/filesystem.hpp>
  8. using namespace std;
  9. using namespace boost::filesystem;
  10. const char * say_what(bool b) { return b ? "true" : "false"; }
  11. int main(int argc, char* argv[])
  12. {
  13. if (argc < 2)
  14. {
  15. cout << "Usage: path_info path-element [path-element...]\n"
  16. "Composes a path via operator/= from one or more path-element arguments\n"
  17. "Example: path_info foo/bar baz\n"
  18. # ifdef BOOST_POSIX_API
  19. " would report info about the composed path foo/bar/baz\n";
  20. # else // BOOST_WINDOWS_API
  21. " would report info about the composed path foo/bar\\baz\n";
  22. # endif
  23. return 1;
  24. }
  25. path p;
  26. for (; argc > 1; --argc, ++argv)
  27. p /= argv[1]; // compose path p from the command line arguments
  28. cout << "\ncomposed path:\n";
  29. cout << " operator<<()---------: " << p << "\n";
  30. cout << " make_preferred()-----: " << p.make_preferred() << "\n";
  31. cout << "\nelements:\n";
  32. for (auto element : p)
  33. cout << " " << element << '\n';
  34. cout << "\nobservers, native format:" << endl;
  35. # ifdef BOOST_POSIX_API
  36. cout << " native()-------------: " << p.native() << endl;
  37. cout << " c_str()--------------: " << p.c_str() << endl;
  38. # else // BOOST_WINDOWS_API
  39. wcout << L" native()-------------: " << p.native() << endl;
  40. wcout << L" c_str()--------------: " << p.c_str() << endl;
  41. # endif
  42. cout << " string()-------------: " << p.string() << endl;
  43. wcout << L" wstring()------------: " << p.wstring() << endl;
  44. cout << "\nobservers, generic format:\n";
  45. cout << " generic_string()-----: " << p.generic_string() << endl;
  46. wcout << L" generic_wstring()----: " << p.generic_wstring() << endl;
  47. cout << "\ndecomposition:\n";
  48. cout << " root_name()----------: " << p.root_name() << '\n';
  49. cout << " root_directory()-----: " << p.root_directory() << '\n';
  50. cout << " root_path()----------: " << p.root_path() << '\n';
  51. cout << " relative_path()------: " << p.relative_path() << '\n';
  52. cout << " parent_path()--------: " << p.parent_path() << '\n';
  53. cout << " filename()-----------: " << p.filename() << '\n';
  54. cout << " stem()---------------: " << p.stem() << '\n';
  55. cout << " extension()----------: " << p.extension() << '\n';
  56. cout << "\nquery:\n";
  57. cout << " empty()--------------: " << say_what(p.empty()) << '\n';
  58. cout << " is_absolute()--------: " << say_what(p.is_absolute()) << '\n';
  59. cout << " has_root_name()------: " << say_what(p.has_root_name()) << '\n';
  60. cout << " has_root_directory()-: " << say_what(p.has_root_directory()) << '\n';
  61. cout << " has_root_path()------: " << say_what(p.has_root_path()) << '\n';
  62. cout << " has_relative_path()--: " << say_what(p.has_relative_path()) << '\n';
  63. cout << " has_parent_path()----: " << say_what(p.has_parent_path()) << '\n';
  64. cout << " has_filename()-------: " << say_what(p.has_filename()) << '\n';
  65. cout << " has_stem()-----------: " << say_what(p.has_stem()) << '\n';
  66. cout << " has_extension()------: " << say_what(p.has_extension()) << '\n';
  67. return 0;
  68. }