os.path.walk and symbolic links

Bernhard Herzog herzog at online.de
Thu Aug 24 13:43:33 EDT 2000


François Pinard <pinard at iro.umontreal.ca> writes:

> Hi, people.
> 
> By any chance, is there a known, or easy idiom so `os.path.walk' would
> follow symbolic links to directories (a bit like `find -follow')?
> 
> If no, I could probably easily simulate it by having the walker function
> to call itself with symbolic link definitions, but then, I would have
> another little problem, as `os.path.join' does not simplify the result
> when its second argument is relative (yet it does the proper thing when
> the second argument is absolute).  For example, with 1.5.2 on Linux:
> 
> >>> os.path.join('/abc/def/ghi', '../xyz')
> '/abc/def/ghi/../xyz'

Well, this is all it can do. If ghi is a symbolic link, this may not be
the same file as /abc/def/xyz

> while I would like to get:
> 
> '/abc/def/xyz'

Just run it through os.path.normpath() after the join.

-- 
Bernhard Herzog   | Sketch, a drawing program for Unix
herzog at online.de  | http://sketch.sourceforge.net/



More information about the Python-list mailing list