[Python-Dev] Issue 11406: adding os.scandir(), a directory iterator returning stat-like info
ronaldoussoren at mac.com
Fri May 10 16:42:49 CEST 2013
On 10 May, 2013, at 16:30, MRAB <python at mrabarnett.plus.com> wrote:
> In the python-ideas list there's a thread "PEP: Extended stat_result"
> about adding methods to stat_result.
> Using that, you wouldn't necessarily have to look at st.st_mode. The method could perform an additional os.stat() if the field was None. For
> # Build lists of files and directories in path
> files = 
> dirs = 
> for name, st in os.scandir(path):
> if st.is_dir():
> That looks much nicer.
I'd prefer a filetype field, with 'st.filetype == "dir"' instead of 'st.is_dir()'. The actual type of filetype values is less important, an enum type would also work although bootstrapping that type could be interesting.
> Python-Dev mailing list
> Python-Dev at python.org
> Unsubscribe: http://mail.python.org/mailman/options/python-dev/ronaldoussoren%40mac.com
More information about the Python-Dev