/* listdir
*
* Small example application which lists all files in a given directory and its
* subdirectories.
*
* It demonstrates the use of the ostream_iterator with the
* filesystem::file_iterator.
*/
/* Note: Do not include config.h in your own programs. See README. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <fs++/file_iterator.h>
#include <iostream>
#include <iterator>
#include <string>
using namespace std ;
int
main (int argc, char** argv)
{
if (argc != 2)
{
cerr << "Usage: listdir /some/directory" << endl ;
return -1 ;
}
string dir (argv[1]) ;
filesystem::file_iterator<> i (dir);
// The file_iterator does not provide the top-level directory during
// iterations, so we output it by hand:
cout << i.currentDirectory () << endl ;
copy (i, i.end (), ostream_iterator<filesystem::file_t> (cout, "\n")) ;
return 0 ;
}
syntax highlighted by Code2HTML, v. 0.9.1