tut2.cpp 997 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // filesystem tut2.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. int main(int argc, char* argv[])
  11. {
  12. if (argc < 2)
  13. {
  14. cout << "Usage: tut2 path\n";
  15. return 1;
  16. }
  17. path p(argv[1]); // avoid repeated path construction below
  18. if (exists(p)) // does path p actually exist?
  19. {
  20. if (is_regular_file(p)) // is path p a regular file?
  21. cout << p << " size is " << file_size(p) << '\n';
  22. else if (is_directory(p)) // is path p a directory?
  23. cout << p << " is a directory\n";
  24. else
  25. cout << p << " exists, but is not a regular file or directory\n";
  26. }
  27. else
  28. cout << p << " does not exist\n";
  29. return 0;
  30. }