Skip to main content

Another library for iterating through the contents of a directory

Project description

dirstree: an another library for iterating through the contents of a directory

Downloads Downloads Coverage Status Lines of code Hits-of-Code Test-Package Python versions PyPI version Checked with mypy Ruff

There are many libraries for traversing directories. You can also do this using the standard library. This particular library is very different in that:

  • Supports filtering by file extensions.
  • Supports filtering in the .gitignore format.
  • Natively works with both Path objects from the standard library and strings.

Table of contents

Installation

You can install dirstree using pip:

pip install dirstree

You can also quickly try out this and other packages without having to install using instld.

Basic usage

It's very easy to work with the library in your own code:

  • Create a crawler object, passing the path to the base directory and, if necessary, additional arguments.
  • Iterate recursively through the files in this directory using the .walk() method.

The simplest code example would look like this:

from dirstree import DirectoryWalker

walker = DirectoryWalker('.')

for file in walker.walk():
    print(file)

Here we output recursively (that is, including the contents of nested directories) all files from the current directory. At each iteration, we get a new Path object.

However, we can iterate not over all files in the directory, but only over files with the extension we need, if we pass the collection with the desired extensions when creating the crawler object:

walker = DirectoryWalker('.', extensions=['.txt'])  # Iterate only on .txt files.

We can also pass a list of exceptions, specifying files or subdirectories for which we will NOT iterate:

walker = DirectoryWalker('.', exclude_patterns=['.git', 'venv'])  # Exclude ".git" and "venv" directories.

Please note that you can specify any files and folders in the .gitignore format.

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

dirstree-0.0.1.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dirstree-0.0.1-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file dirstree-0.0.1.tar.gz.

File metadata

  • Download URL: dirstree-0.0.1.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dirstree-0.0.1.tar.gz
Algorithm Hash digest
SHA256 250e7d2524dff22b1c0aeb0ed9d045373e37f6150915d23e9b039204888c68b6
MD5 2c55a84c3d7dfddc3ad9bde7c92c2c53
BLAKE2b-256 c3b8d137b02bc2e7ec0e1ad7883de27a97ca4b0209d7eddf6556fcef3634e92e

See more details on using hashes here.

Provenance

The following attestation bundles were made for dirstree-0.0.1.tar.gz:

Publisher: release.yml on pomponchik/dirstree

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dirstree-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: dirstree-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dirstree-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 caa0156fd209d1178c784a06ac10792bfec69f80291d8729a427b7faa849a98e
MD5 6cb0749409b1418f41bf24a95fa7da39
BLAKE2b-256 c48339d7d560dff481376e06a1d2d3c25bf8cc38ed0047c82e5627954eecc2f0

See more details on using hashes here.

Provenance

The following attestation bundles were made for dirstree-0.0.1-py3-none-any.whl:

Publisher: release.yml on pomponchik/dirstree

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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