file_size.cpp 1021 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // file_size program -------------------------------------------------------//
  2. // Copyright Beman Dawes, 2004
  3. // Use, modification, and distribution is subject to the Boost Software
  4. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. // See http://www.boost.org/libs/filesystem for documentation.
  7. #include <boost/filesystem/operations.hpp>
  8. #include <iostream>
  9. namespace fs = boost::filesystem;
  10. int main( int argc, char* argv[] )
  11. {
  12. if ( argc != 2 )
  13. {
  14. std::cout << "Usage: file_size path\n";
  15. return 1;
  16. }
  17. std::cout << "sizeof(intmax_t) is " << sizeof(boost::intmax_t) << '\n';
  18. fs::path p( argv[1] );
  19. if ( !fs::exists( p ) )
  20. {
  21. std::cout << "not found: " << argv[1] << std::endl;
  22. return 1;
  23. }
  24. if ( !fs::is_regular( p ) )
  25. {
  26. std::cout << "not a regular file: " << argv[1] << std::endl;
  27. return 1;
  28. }
  29. std::cout << "size of " << argv[1] << " is " << fs::file_size( p )
  30. << std::endl;
  31. return 0;
  32. }