os.walk restart

Steven D'Aprano steven at REMOVE.THIS.cybersource.com.au
Thu Mar 18 05:04:46 CET 2010


On Wed, 17 Mar 2010 20:08:48 -0700, alex23 wrote:

> Steven D'Aprano <ste... at REMOVE.THIS.cybersource.com.au> wrote:
>> # Untested
>> last_visited = open("last_visited.txt", 'r').read()
>> for root, dirs, files in os.walk(last_visited or basedir):
>>      open("last_visited.txt", 'w').write(root) run program
> 
> Wouldn't this only walk the directory the exception occured in and not
> the remaining unwalked dirs from basedir?

Only if you have some sort of branching file hierarchy with multiple sub-
directories in the one directory, instead of a nice simple linear chain 
of directories a/b/c/d/.../z as nature intended.

*wink*

Yes, good catch. I said it was untested. You might be able to save the 
parent of the current directory, and restart from there instead.


-- 
Steven



More information about the Python-list mailing list