confusion regarding os.path.walk()

Andrew Brown killspam at darwinwars.com
Tue Feb 19 13:21:14 EST 2002


> I think perhaps you both are somehow thinking that os.path.walk
> changes it's current directory as it 'walks' the tree: it doesn't.
> 
Tuesday, February 19, 2002, 18:02:08, you wrote:

S> The current working directory stays the same and all relative
S> paths are relative to it. When os.path.walk gives you a directory
S> and a list of files in that directory, unless that directory is
S> your current working directory, you need to either join the paths
S> or change your working directory to access the files.


Thanks for your help. What you describe is what I thought should
happen. But I couldn't figure out how to join the paths. It always
looked right: I'd do debugging runs that simply printed out the
command it was supposed to execute, and I could get results like

'ln -s ./wombats/habitat/burrows.html ./wombats/habitat/Burrows.htm'

(which I think should work) but when I ran this through os.system(),
it failed every time. So did every other variant I could think of
except changing to the directory where the file was and linking
without any paths involved.




More information about the Python-list mailing list