1
// path_info.cpp ---------------------------------------------------------------------//
3
// Copyright Beman Dawes 2009
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/filesystem.hpp>
13
using namespace boost::filesystem;
15
const char * say_what(bool b) { return b ? "true" : "false"; }
17
int main(int argc, char* argv[])
21
cout << "Usage: path_info path-portion...\n"
22
"Example: path_info foo/bar baz\n"
23
# ifdef BOOST_POSIX_API
24
" would report info about the composed path foo/bar/baz\n";
25
# else // BOOST_WINDOWS_API
26
" would report info about the composed path foo/bar\\baz\n";
31
path p; // compose a path from the command line arguments
33
for (; argc > 1; --argc, ++argv)
36
cout << "\ncomposed path:\n";
37
cout << " cout << -------------: " << p << "\n";
38
cout << " make_preferred()----------: " << path(p).make_preferred() << "\n";
40
cout << "\nelements:\n";
42
for (path::iterator it(p.begin()), it_end(p.end()); it != it_end; ++it)
43
cout << " " << *it << '\n';
45
cout << "\nobservers, native format:" << endl;
46
# ifdef BOOST_POSIX_API
47
cout << " native()-------------: " << p.native() << endl;
48
cout << " c_str()--------------: " << p.c_str() << endl;
49
# else // BOOST_WINDOWS_API
50
wcout << L" native()-------------: " << p.native() << endl;
51
wcout << L" c_str()--------------: " << p.c_str() << endl;
53
cout << " string()-------------: " << p.string() << endl;
54
wcout << L" wstring()------------: " << p.wstring() << endl;
56
cout << "\nobservers, generic format:\n";
57
cout << " generic_string()-----: " << p.generic_string() << endl;
58
wcout << L" generic_wstring()----: " << p.generic_wstring() << endl;
60
cout << "\ndecomposition:\n";
61
cout << " root_name()----------: " << p.root_name() << '\n';
62
cout << " root_directory()-----: " << p.root_directory() << '\n';
63
cout << " root_path()----------: " << p.root_path() << '\n';
64
cout << " relative_path()------: " << p.relative_path() << '\n';
65
cout << " parent_path()--------: " << p.parent_path() << '\n';
66
cout << " filename()-----------: " << p.filename() << '\n';
67
cout << " stem()---------------: " << p.stem() << '\n';
68
cout << " extension()----------: " << p.extension() << '\n';
71
cout << " empty()--------------: " << say_what(p.empty()) << '\n';
72
cout << " is_absolute()--------: " << say_what(p.is_absolute()) << '\n';
73
cout << " has_root_name()------: " << say_what(p.has_root_name()) << '\n';
74
cout << " has_root_directory()-: " << say_what(p.has_root_directory()) << '\n';
75
cout << " has_root_path()------: " << say_what(p.has_root_path()) << '\n';
76
cout << " has_relative_path()--: " << say_what(p.has_relative_path()) << '\n';
77
cout << " has_parent_path()----: " << say_what(p.has_parent_path()) << '\n';
78
cout << " has_filename()-------: " << say_what(p.has_filename()) << '\n';
79
cout << " has_stem()-----------: " << say_what(p.has_stem()) << '\n';
80
cout << " has_extension()------: " << say_what(p.has_extension()) << '\n';