May 11, 2013
1:29 a.m.
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
example:
# Build lists of files and directories in path files = [] dirs = [] for name, st in os.scandir(path): if st.is_dir(): dirs.append(name) else: files.append(name)
That's not too bad. However, the st.is_dir() function could potentially call os.stat(), so you'd have to be specific about how errors are handled. Also, I'm not too enthusiastic about how much "API weight" this would add -- do you need st.is_link() and st.size() and st.everything_else() as well? -Ben