scandir()
is a directory iteration function likeos.listdir()
, except that instead of returning a list of bare filenames, it yieldsDirEntry
objects that include file type and stat information along with the name. Usingscandir()
increases the speed ofos.walk()
by 2-20 times (depending on the platform and file system) by avoiding unnecessary calls toos.stat()
in most cases.
scandir
has been included in the Python 3.5 standard library asos.scandir()
, and the related performance improvements toos.walk()
have also been included. So if you're lucky enough to be using Python 3.5 (release date September 13, 2015) you get the benefit immediately, otherwise justdownload this module from PyPI <https://pypi.python.org/pypi/scandir>
_, install it withpip install scandir
, and then do something like this in your code::try: from os import scandir, walk except ImportError: from scandir import scandir, walk
PEP 471 <https://www.python.org/dev/peps/pep-0471/>
, which is the PEP that proposes includingscandir
in the Python standard library, wasaccepted <https://mail.python.org/pipermail/python-dev/2014-July/135561.html>
in July 2014 by Victor Stinner, the BDFL-delegate for the PEP.This
scandir
module is intended to work on Python 2.6+ and Python 3.2+ (and it has been tested on those versions).
Package Version | Update ID | Released | Package Hub Version | Platforms | Subpackages |
---|---|---|---|---|---|
1.10.0-3.16.1 info | SUSE-SLE-Module-Packagehub-Subpackages-15-SP2-2021-985 | 2021-03-30 | 15 SP2 Subpackages Updates |
|
|
1.10.0-bp153.1.60 info | GA Release | 2021-03-05 | 15 SP3 |
|
|
1.10.0-bp152.1.1 info | GA Release | 2020-04-17 | 15 SP2 |
|
|
1.9.0-bp151.1.14 info | GA Release | 2019-07-17 | 15 SP1 |
|
|
1.7-bp150.2.4 info | GA Release | 2018-07-30 | 15 |
|
|