os.walk restart

MRAB python at mrabarnett.plus.com
Wed Mar 17 23:34:46 EDT 2010


Keir Vaughan-taylor wrote:
> I am traversing a large set of directories using
> 
> for root, dirs, files in os.walk(basedir):
>     run program
> 
> Being a huge directory set the traversal is taking days to do a
> traversal.
> Sometimes it is the case there is a crash because of a programming
> error.
> As each directory is processed the name of the directory is written to
> a file
> I want to be able to restart the walk from the directory where it
> crashed.
> 
> Is this possible?

I would write my own walker which sorts the directory entries it finds
before walking them and can skip the entries until it gets to the
desired starting path, eg if I want to start at "/foo/bar" then skip
over the entries in the root directory which start with a name before
"foo" and the entries in the subdirectory "/foo" which start with a name
before "bar".



More information about the Python-list mailing list