I have this program where I'm trying to find the file size with the boost library. I find the files fine, but it won't get the file's size, where am I wrong? Thanx for your help...
Here's my code so far.
It compiles fine, but won't return the file size.
#include <boost/filesystem.hpp>
namespace bf = boost::filesystem;
#include <iostream>
#include <stdio.h>
using namespace std;
int main( int argc, char* argv[] ) {
bf::path fullpath( bf::initial_path() );//create new filesystem path
if( argc > 1 )
fullpath = bf::system_complete(bf::path( argv[1], bf::native ) );//turns given filename into reference
//and sees if it is sctually there.
if( !bf::exists( fullpath ) ) {
cout << "Could not find: " << fullpath.native_file_string() << endl;//returns in native format
}//end if
if( bf::is_directory( fullpath ) ) {
cout << "In directory: " << fullpath << endl;
bf::directory_iterator dirIter( fullpath );//recursive_directory looks into folder/next folder/ ect...
bf::directory_iterator endIter;
for( ; dirIter != endIter; ++dirIter ) {
//trap file or folder name your not allowed to read
try {
cout << dirIter->filename() << endl;
} catch( std::exception const& ex ) {
cerr << dirIter->filename() << " " << ex.what() << endl;
}//end catch
}//end for
}//end if
else {
cout << "\Found: " << fullpath.native_file_string() << endl;
}//end if else
cout << fullpath << endl;
//check file size
if ( argc != 2 ) {
cout << "usage: file_size path\n";
return 1;
}//end if
// print out size of intmax_t
cout << "sizeof(intmax_t) is " << sizeof(boost::intmax_t) << '\n';
//error checking...
if ( !bf::exists( fullpath ) ) {
cout << "not found: " << argv[1] << endl;
return 1;
}//end if
if ( !bf::is_regular( fullpath ) ) {
cout << "not a regular file: " << fullpath.native_file_string() << endl;
return 1;
}//end if
cout << "size of " << argv[1] << " is " << bf::file_size( fullpath ) << endl;
return 1;
}//end main