Walk directories trees with os.scandir, generating DirEntry objects
Project description
scanwalk
scanwalk.walk()
walks a directory tree, generating DirEntry
objects.
It's an alternative to os.walk()
modelled on os.scandir()
.
>>> import scanwalk
>>> for entry in scanwalk.walk('data/demo'):
... print(entry.path, entry.name, entry.is_dir(), entry.is_file())
...
data/demo demo True False
data/demo/adir adir True False
data/demo/adir/anotherfile anotherfile False True
data/demo/adir/anotherdir anotherdir True False
data/demo/afile afile False True
a rough equivalent with os.walk()
would be
>>> import os
>>> for parent, dirs, files in os.walk('data/demo'):
... print(parent, name, True, False)
... for name in dirs:
... print(os.path.join(parent, name), name, True, False)
... for name in files:
... print(os.path.join(parent, name), name, False, True)
...
data/demo demo True False
data/demo/adir adir True False
data/demo/afile afile False True
data/demo/adir/anotherdir anotherdir True False
data/demo/adir/anotherfile anotherfile False True
Notable features and differences between scanwalk.walk()
and os.walk()
scanwalk
generates a flat stream ofDirEntry
objects. Nested loops aren't needed.scanwalk
doesn't sort entries. Directories and files are intermingled (within a given parent directory).scanwalk
descends directories as it encounters them. It's neither depth first or breadth first.os.walk()
supports both.scanwalk
doesn't build intermediate listsscanwalk
doesn't need anonerror()
callback.scanwalk
can be 10-20% faster.
Installation
python -m pip install scanwalk
Requirements
- Python 3.6+
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
scanwalk-0.0.2.tar.gz
(3.3 kB
view details)
Built Distribution
File details
Details for the file scanwalk-0.0.2.tar.gz
.
File metadata
- Download URL: scanwalk-0.0.2.tar.gz
- Upload date:
- Size: 3.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 925ad755a80252a7aac7e1fff62174a5efda47dbbacafa8591805b9d5c85546a |
|
MD5 | 88b4ae388e2172ad600b8826b05e8dc9 |
|
BLAKE2b-256 | 3a9eacce065204832f5c0d1f8f960cdd3c1a28d60a8e0a05d6a35009061454e5 |
File details
Details for the file scanwalk-0.0.2-py2.py3-none-any.whl
.
File metadata
- Download URL: scanwalk-0.0.2-py2.py3-none-any.whl
- Upload date:
- Size: 3.6 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9ec639e5dd1da149065c85aadf1b44bcaf2ff99a744bd7367796a4b248178575 |
|
MD5 | 266f65a19c2cb2b256fabaea7f78a722 |
|
BLAKE2b-256 | 81abe62f69709e4c113550930c6f48d65354cea7c68c0a8104ac1e5bbf627191 |