[Python-ideas] Speed up os.walk() 5x to 9x by using file attributes from FindFirst/NextFile() and readdir()

Ronald Oussoren ronaldoussoren at mac.com
Tue Nov 13 10:06:30 CET 2012


On 13 Nov, 2012, at 8:13, Ben Hoyt <benhoyt at gmail.com> wrote:

>> Where would st_mode be retrieved from?  The readdir(3) interface
>> only provides d_type (and that field is not in POSIX or SUS).
>> 
>> The d_type field contains a file type, and while you could use that
>> to construct a value for st_mode that can be used to test the file
>> type, you cannot reconstruct the file permissions from that.
> 
> Yes, you're right. The amount of information in st_mode would be
> implementation dependent. I don't see a huge problem with that -- it's
> already true for os.stat(), because on Windows stat()'s st_mode
> contains a much more limited subset of info than on POSIX systems.

It would be very odd to have an st_mode that contains a subset of 
the information the platform can provide. In particular having st_mode
would give the impression that it is the full mode.

Why not return the information that can be cheaply provided, is useful
and can be provided by major platforms (at least Windows, Linux and
OS X)?  And "useful" would be information for which there is a clear 
usecase, such as the filetype as it can significantly speed up os.walk.

OTOH, FindNextFile on Windows can return most information in struct stat.

Ronald




More information about the Python-ideas mailing list