1 // filesystem tut2.cpp ---------------------------------------------------------------// 2 3 // Copyright Beman Dawes 2009 4 5 // Distributed under the Boost Software License, Version 1.0. 6 // See http://www.boost.org/LICENSE_1_0.txt 7 8 // Library home page: http://www.boost.org/libs/filesystem 9 10 #include <iostream> 11 #include <boost/filesystem.hpp> 12 using namespace std; 13 using namespace boost::filesystem; 14 main(int argc,char * argv[])15int main(int argc, char* argv[]) 16 { 17 if (argc < 2) 18 { 19 cout << "Usage: tut2 path\n"; 20 return 1; 21 } 22 23 path p(argv[1]); // avoid repeated path construction below 24 25 if (exists(p)) // does path p actually exist? 26 { 27 if (is_regular_file(p)) // is path p a regular file? 28 cout << p << " size is " << file_size(p) << '\n'; 29 30 else if (is_directory(p)) // is path p a directory? 31 cout << p << " is a directory\n"; 32 33 else 34 cout << p << " exists, but is not a regular file or directory\n"; 35 } 36 else 37 cout << p << " does not exist\n"; 38 39 return 0; 40 } 41