Boost logo

Boost Users :

Subject: Re: [Boost-users] questions about recursing a directory tree
From: Zsolt Ero (zsolt.ero_at_[hidden])
Date: 2010-11-25 02:28:43


OK, this is the easiest example which produces the "access is denied"
error, I can come up with:

int main() {
 fs::recursive_directory_iterator it_end;
 fs::recursive_directory_iterator it_dir("e:\\");

  for ( ; it_dir != it_end; ++it_dir ) {
  //something here
  }
}

Can someone tell me any solution which would catch a "access is denied"
kind of error _inside_ the for loop? For every other error it works if
I just do a try-catch _inside_ the for loop, but a not accessible
directory produces error outside the loop?

Or if it's not possible to catch the error inside, how could I start
the for cycle again after it has been caught?

Zsolt

On Tue, Nov 23, 2010 at 12:48 PM, Zsolt Ero <zsolt.ero_at_[hidden]> wrote:
> OK, I figured out my way, it seems that I could solve most of the
> problems. My big problem now is that the recursive_directory_iterator
> goes through a file which has a really long name. I think it's more
> than 256 characters. It says:
>
> boost::filesystem::last_write_time: The system cannot find the path specified:
>
> Is there a fix or something for boost to handle more than 256
> characters in windows path? I am using MSVC2010 + latest Boostpro
> installer.
>
> Zsolt
>
> p.s. so far here is my code. If you have any idea about what I am
> doing wrong, please don't hesitate to comment:
>
> #define BOOST_FILESYSTEM_VERSION 3
>
> #include "boost/filesystem.hpp"
> #include <iostream>
> #include <ctime>
>
>
> using namespace std;
> namespace fs = boost::filesystem;
>
>
> int main() {
>        fs::recursive_directory_iterator it_end;
>        fs::recursive_directory_iterator it_dir("e:\\");
>        fs::path p;
>
>        time_t oldest( time(NULL) );
>        time_t newest(0);
>
>        try {
>                for ( ; it_dir != it_end; ++it_dir ) {
>                        p = *it_dir;
>                        try {
>                                time_t t( last_write_time(p) );
>                                if (t<oldest) oldest=t;
>                                if (t>newest) newest=t;
>                                //if (fs::is_directory(p)) cout << (p) << " " << t << endl;
>                        }
>
>                        catch (const fs::filesystem_error& ex) {
>                                cout << "\n" << ex.what() << "\n";
>                        }
>                }
>        }
>
>        catch (const fs::filesystem_error& ex) {
>                cout << "\n" << ex.what() << "\n";
>        }
>
>        cout << "\nOldest: " << ctime(&oldest);
>        cout << "Newest: " << ctime(&newest) << endl;
>
>        return 0;
> }
>


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net