-----Original Message----- From: Erik [mailto:firstname.lastname@example.org] Sent: Thursday, November 26, 2015 15:22 To: python-ideas Subject: [Python-ideas] PEP471 - (os.scandir())
PEP471 introduces a faster way of doing low-level directory traversal which is then used to implement and speed up the higher-level API os.walk() - which for me at least is the "go to API" for most directory scanning code I write.
However, when using os.walk() the first thing that one tends to do with the results is to analyse them in some way (look at file sizes, datestamps and other things that stat() returns) which is exactly the information that os.scandir() is caching and speeding up but which is then thrown away in order to emulate os.walk()'s original name-based API (well, name and type as the directory/file distinction is also there).
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.