On 23/12/15 00:23, Guido van Rossum wrote:
So, perhaps the pathlib.Path class needs to have some way to take in a DirEntry produced by os.scandir() and a flag to allow it to cache stat() results? Then we could easily write a pathlib.walk() function that's like os.walk() but returning caching Path objects.
Yes please. I raised this recently in a thread that died (but with no negative responses - see below). I started looking at the various modules to try to bring the whole thing together into a reasonable proposal, but it was just a can of worms (glob, fnmatch, pathlib, os.scandir, os.walk, os.fwalk, fts ...). I'm afraid I don't have the free cycles to try to tackle that, so I ducked out. It would be great if all of that could be somehow brought together into a cohesive filesystem module.
On 27/11/15 13:49, Eric Fahlgren wrote:
-----Original Message----- From: Erik
So, I'd like to suggest an os.walk()-like API that returns the os.scandir() DirEntry structures rather than names (*). I have my own local version that's just a copy of os.walk() that appends "entry" rather than "entry.name" to the returned lists, but that's a nasty way of achieving this.
How to do it -
os.walk() "direntries=True" keyword? os.walkentries() function? Something else better than those?
"walk" + "scandir" = "walkdir"???
I'm definitely +1 on this, as it is fresh on my mind, too. I just converted our build tools over to use a homebrew walk as you did, and now use DirEntry instead of path names almost exclusively.