|
-
June 7th, 2013, 06:24 PM
#1
Question about listing files with boost filesystem
Hi All,
I have the following code which is based of the tut3.cpp example at: http://www.boost.org/doc/libs/1_46_1...tory-iteration
However, I'm not entirely sure how to retrieve the full file path which I'd like to use to get the file size. So essentially the aim is to go through a directory and list all the file sizes. Any help would be greatly appriciated, thanks
Code:
if (exists(p)) {
if (is_directory(p)) {
cout << p << " is a directory containing:\n";
copy(directory_iterator(p), directory_iterator(), // directory_iterator::value_type
ostream_iterator<directory_entry>(cout, "\n")); // is directory_entry, which is
// path stream inserter
if (is_regular_file(p)) {
cout << p << " size is " << file_size(p) << '\n';
}
}
-
June 7th, 2013, 06:47 PM
#2
Re: Question about listing files with boost filesystem
Ah, think I've solved it, the following seems to provide a nice list with itr->path() containing the absolute file path
Code:
if (exists(p)) {
if (is_directory(p)) {
cout << p << " is a directory containing:\n";
directory_iterator end_itr; // default construction yields past-the-end
for (directory_iterator itr( p );
itr != end_itr;
++itr )
{
cout << "file: " << itr->path() << endl;
}
/*if (is_regular_file(directory_entry)) {
cout << p << " size is " << file_size(p) << '\n';
}*/
} else {
cout << p << "Can not train, this is not a directory\n";
}
} else {
cout << p << " does not exist\n";
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|