Another library for iterating through the contents of a directory
Project description
dirstree: an another library for iterating through the contents of a directory
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
.gitignoreformat. - Natively works with both
Pathobjects 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
250e7d2524dff22b1c0aeb0ed9d045373e37f6150915d23e9b039204888c68b6
|
|
| MD5 |
2c55a84c3d7dfddc3ad9bde7c92c2c53
|
|
| BLAKE2b-256 |
c3b8d137b02bc2e7ec0e1ad7883de27a97ca4b0209d7eddf6556fcef3634e92e
|
Provenance
The following attestation bundles were made for dirstree-0.0.1.tar.gz:
Publisher:
release.yml on pomponchik/dirstree
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dirstree-0.0.1.tar.gz -
Subject digest:
250e7d2524dff22b1c0aeb0ed9d045373e37f6150915d23e9b039204888c68b6 - Sigstore transparency entry: 566660275
- Sigstore integration time:
-
Permalink:
pomponchik/dirstree@3791aa9a542c13fb6b7e45682b07286e34b69a2a -
Branch / Tag:
refs/heads/main - Owner: https://github.com/pomponchik
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@3791aa9a542c13fb6b7e45682b07286e34b69a2a -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
caa0156fd209d1178c784a06ac10792bfec69f80291d8729a427b7faa849a98e
|
|
| MD5 |
6cb0749409b1418f41bf24a95fa7da39
|
|
| BLAKE2b-256 |
c48339d7d560dff481376e06a1d2d3c25bf8cc38ed0047c82e5627954eecc2f0
|
Provenance
The following attestation bundles were made for dirstree-0.0.1-py3-none-any.whl:
Publisher:
release.yml on pomponchik/dirstree
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dirstree-0.0.1-py3-none-any.whl -
Subject digest:
caa0156fd209d1178c784a06ac10792bfec69f80291d8729a427b7faa849a98e - Sigstore transparency entry: 566660278
- Sigstore integration time:
-
Permalink:
pomponchik/dirstree@3791aa9a542c13fb6b7e45682b07286e34b69a2a -
Branch / Tag:
refs/heads/main - Owner: https://github.com/pomponchik
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@3791aa9a542c13fb6b7e45682b07286e34b69a2a -
Trigger Event:
push
-
Statement type: