[Python-Dev] PEP 471 -- os.scandir() function -- a better and faster directory iterator

Akira Li 4kir4.1i at gmail.com
Sat Jun 28 15:05:31 CEST 2014

Ben Hoyt <benhoyt at gmail.com> writes:

> Hi Python dev folks,
> I've written a PEP proposing a specific os.scandir() API for a
> directory iterator that returns the stat-like info from the OS, *the
> main advantage of which is to speed up os.walk() and similar
> operations between 4-20x, depending on your OS and file system.*
> ...
> http://legacy.python.org/dev/peps/pep-0471/
> ...
> Specifically, this PEP proposes adding a single function to the ``os``
> module in the standard library, ``scandir``, that takes a single,
> optional string as its argument::
>     scandir(path='.') -> generator of DirEntry objects

Have you considered adding support for paths relative to directory
descriptors [1] via keyword only dir_fd=None parameter if it may lead to
more efficient implementations on some platforms?

[1]: https://docs.python.org/3.4/library/os.html#dir-fd


More information about the Python-Dev mailing list