On Mon, Jan 4, 2016 at 9:25 PM, Guido van Rossum email@example.com wrote:
Following up on this, in theory the right way to walk a tree using pathlib already exists, it's the rglob() method. E.g. all paths under /foo/bar should be found as follows:
for path in pathlib.Path('/foo/bar').rglob('**/*'):
[actually, rglob('*') or glob('**/*')]
The PermissionError bug you found is already reported: http://bugs.python.org/issue24120 -- it even has a patch but it's stuck in review.
I committed this fix.
Sadly there's another error: loops introduced by symlinks cause infinite recursion. I filed that here: http://bugs.python.org/issue26012. (The fix should be judicious use of is_symlink(), but the code is a little convoluted.)
I committed a fix for this too (turned out to need just one call to is_symlink()).
I also added a .path attribute to pathlib.*Path objects, so that p.path == str(p). You can now use the idiom getattr(arg, 'path', arg) to extract the path from a pathlib.Path object, or from an os.DirEntry object, or fall back to a plain string, without using str(arg), which would turn *any* object into a string, which is never what you want to happen by default.
These changes will be released in Python 3.4.5, 3.5.2 and 3.6.