Skip to main content

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 of DirEntry 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 lists
  • scanwalk doesn't need an onerror() 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.3.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

scanwalk-0.0.3-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

Details for the file scanwalk-0.0.3.tar.gz.

File metadata

  • Download URL: scanwalk-0.0.3.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

Hashes for scanwalk-0.0.3.tar.gz
Algorithm Hash digest
SHA256 3edc08760a2e3e8a7d6161da6f2d92d1a30054f24ef9361441b314f642baa2be
MD5 31dae01e253b4c0b412056350166ab93
BLAKE2b-256 5b9165a0be81a07ef4ac2c3ec6418449d2aeb90974acfae89e1ab0ae7cad5020

See more details on using hashes here.

File details

Details for the file scanwalk-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: scanwalk-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 3.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.5

File hashes

Hashes for scanwalk-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 1e6f59925daeebab333d9b1c22a27071292d0735e5283d4c77744d6b78927f7d
MD5 841539a95d939a9df35e6525416eb03e
BLAKE2b-256 459beb733bad77578deadaba1513d1e8c0627f78bf5062ec3950cbc1a4fb7bd1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page