Small utilities for listing files in directories
Project description
fileutils
A minimalist, fluent Python library for listing and filtering files.
The fileutils library provides a clean, chainable interface to explore directories, filter by extensions, or utilize predefined file categories.
Features
- Fluent API: Chainable methods designed for high readability and maintainability.
- Smart Filtering: Filter by extension or semantic categories (e.g.,
code,data,image). - Recursive Support: Deep-search directory structures with a single method call.
- Hidden Files: Comprehensive control over the visibility of dotfiles.
- Modern Python Implementation: Built-in support for
pathlib.Pathand comprehensive type hinting.
Installation
pip install fileutils-dir
Usage
The in_dir function returns a query object, providing a descriptive and readable approach to listing or counting files.
1. Basic Listing
from fileutils import in_dir
# List all files in the current directory
files = in_dir().list()
# List all Python files
python_files = in_dir(ext="py").list()
2. Semantic Filtering
Filter files based on their purpose rather than just file extensions.
# List all images and videos
media = in_dir(dtype=["image", "video"]).list()
# Count all data files in a specific folder
count = in_dir(path="data", dtype="data").count()
3. Recursive and Hidden Files
# Find all configuration files recursively, including hidden files
config_files = (
in_dir(path="project")
.recursive()
.show_hidden()
.list()
)
API Reference
in_dir(path=".", *, ext=None, dtype=None)
Initializes a DirQuery object.
path: The target directory path (defaults to current directory".").ext: A string or list of extensions (e.g.,"py",[".js", "ts"]).dtype: A string or list of file categories (e.g.,"code","image").
DirQuery Methods
.recursive(): Configures the query to traverse all subdirectories..show_hidden(): Includes files starting with a dot (.) in the results..list(): Executes the query and returns alist[str]of matching file paths..count(): Executes the query and returns the total number of matching files.
Supported Categories (dtype)
| Category | Extensions |
|---|---|
image |
.jpg, .jpeg, .png, .webp, .bmp, .gif, .tiff |
text |
.txt, .md, .rst, .log |
pdf |
|
doc |
.doc, .docx, .odt |
sheet |
.xls, .xlsx, .ods, .csv |
presentation |
.ppt, .pptx, .odp |
code |
.py, .js, .ts, .java, .c, .cpp, .h, .go, .rs, .rb, .php, .sh |
data |
.json, .yaml, .yml, .xml, .toml |
audio |
.mp3, .wav, .flac, .ogg, .aac, .m4a |
video |
.mp4, .mkv, .avi, .mov, .webm |
archive |
.zip, .tar, .gz, .bz2, .7z, .rar |
License
This project is licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
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 fileutils_dir-0.6.0.tar.gz.
File metadata
- Download URL: fileutils_dir-0.6.0.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c26bd2c9f80a52e6334392db2c12ec5b88c11e38216092236ff2cce36f69bc05
|
|
| MD5 |
354b6374d8355d99f0b6479bc5a16019
|
|
| BLAKE2b-256 |
60b22c871c5d5d3c93273202524b012c8ed137c24e9e05ce8309ed14b2275c47
|
File details
Details for the file fileutils_dir-0.6.0-py3-none-any.whl.
File metadata
- Download URL: fileutils_dir-0.6.0-py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
52f8418846f9a3e9e57b4b567ae9d6ba2fc23d2496da5ee9e0c15ec9793a257d
|
|
| MD5 |
109a1ac53a71843e6cfd2e6cb2fea88e
|
|
| BLAKE2b-256 |
b8dad1f0e07b5e8e1d15f1140df21624c94745fb8e5a275627ab0d2c6a697527
|