diff options
author | Georg Brandl <georg@python.org> | 2007-03-16 08:22:40 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2007-03-16 08:22:40 (GMT) |
commit | 8844e438b1e0a3546f15213df7741c3141859eeb (patch) | |
tree | 9e11e3f32ead5bd309c3c1429a98be2be559d01b /Lib/os.py | |
parent | 8f06d02935939629209b303a8ec54cf2db0cc302 (diff) | |
download | cpython-8844e438b1e0a3546f15213df7741c3141859eeb.zip cpython-8844e438b1e0a3546f15213df7741c3141859eeb.tar.gz cpython-8844e438b1e0a3546f15213df7741c3141859eeb.tar.bz2 |
Patch #1273829: os.walk() now has a "followlinks" parameter. If set to
True (which is not the default), it visits symlinks pointing to
directories.
Diffstat (limited to 'Lib/os.py')
-rw-r--r-- | Lib/os.py | 10 |
1 files changed, 7 insertions, 3 deletions
@@ -221,7 +221,7 @@ def renames(old, new): __all__.extend(["makedirs", "removedirs", "renames"]) -def walk(top, topdown=True, onerror=None): +def walk(top, topdown=True, onerror=None, followlinks=False): """Directory tree generator. For each directory in the directory tree rooted at top (including top @@ -257,6 +257,10 @@ def walk(top, topdown=True, onerror=None): to abort the walk. Note that the filename is available as the filename attribute of the exception object. + By default, os.walk does not follow symbolic links to subdirectories on + systems that support them. In order to get this functionality, set the + optional argument 'followlinks' to true. + Caution: if you pass a relative pathname for top, don't change the current working directory between resumptions of walk. walk never changes the current directory, and assumes that the client doesn't @@ -300,8 +304,8 @@ def walk(top, topdown=True, onerror=None): yield top, dirs, nondirs for name in dirs: path = join(top, name) - if not islink(path): - for x in walk(path, topdown, onerror): + if followlinks or not islink(path): + for x in walk(path, topdown, onerror, followlinks): yield x if not topdown: yield top, dirs, nondirs |