I've been trying all night to get this to work, but everything i do give me a compile or runtime error.
currently I'm using file_size() (no idea what to include inside the brackets).
Also if you have can help with any of the following it would help me greatly:
-list the files in reverse order
-show all files (including hidden files)(dont know if its doing that now, if so then i need to switch it so its off by default)
-how to display the filename (example.txt)
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
using namespace boost::filesystem;
#include <boost/regex.hpp>
void show_files_withR( const path & directory, bool recurse_into_subdirs = true)
{
if( exists( directory ) )
{
directory_iterator end ;
for( directory_iterator iter(directory) ; iter != end ; ++iter )
if ( is_directory( *iter ) )
{
cout << "\nd: " << setw(5) << right << iter->path() ;
if( recurse_into_subdirs ) show_files_withR(*iter) ;
}
else
cout << "\n-: " << setw(5) << right << iter->path() ;
}
}
int main(int argc, char *argv[])
{
if (argc != 4)
{
cout << "Usage: program.exe [switches] [path] [filespec]" << endl;
}
else
{
string s_switches(argv[1]);
string s_path(argv[2]);
string s_filespec(argv[3]);
bool aSwitch = false;
bool rSwitch = false;
bool RSwitch = false;
bool lSwitch = false;
//set switches
if (s_switches == "-a")
{
bool aSwitch = true;
cout << "switch -a is: " << aSwitch << endl;
}
if (s_switches == "-r")
{
bool rSwitch = true;
cout << "switch -r is: " << rSwitch << endl;
}
if (s_switches == "-R")
{
bool RSwitch = true;
cout << "switch -R is: " << RSwitch << endl;
}
if (s_switches == "-l")
{
bool lSwitch = true;
cout << "switch -l is: " << lSwitch << endl;
}
//boost::regex expr(s_filespec);
//fs::path currentPath(s_path);
//cout << currentPath << endl;
//fs::basic_directory_iterator(s_path);
//uintmax_t file_size(const path&)
const path & directory = s_path;
if( exists( directory ) )
{
directory_iterator end;
for( directory_iterator iter(directory) ; iter != end ; ++iter )
if ( is_directory( *iter ) )
{
cout << "\nd: " << setw(5) << right << file_size(s_path) << iter->path();
if(RSwitch) show_files_withR(*iter);
}
else
cout << "\n-: " << setw(5) << right << iter->path();
}
}
cin.ignore();
return 0;
}