Small utilities for listing files in directories
Project description
fileutils
fileutils is a minimalist Python library for selecting files from directories using a fluent, chainable API.
It is designed as a feeder tool for application pipelines — helping you declaratively select the right set of file paths to hand off to downstream processing.
Scope & Non-Goals
fileutils is intentionally limited in scope.
It does NOT:
- modify the filesystem
- delete, move, or rename files
- parse file contents
- perform cleanup or disk management
It DOES:
- traverse directories
- filter files by name, extension, or semantic type
- return predictable, composable sets of paths
Installation
pip install fileutils-dir
Core Concept
The primary entry point is in_dir(), which returns a DirQuery object.
You progressively narrow a candidate set of files using chainable selectors, then execute the query.
from fileutils import in_dir
files = (
in_dir("src")
.recursive()
.include_type("code")
.include_ext("py")
.exclude_ext("log")
.list()
This produces a list of file paths suitable for further processing.
Basic Usage
List Files in a Directory
files = in_dir().list()
Filter by Extension
python_files = in_dir().include_ext("py").list()
web_files = in_dir().include_ext("html", "css", "js").list()
Semantic Filtering (Types)
Instead of manually listing extensions, you can filter by semantic category.
media = in_dir().include_type("image", "video").list()
data_files = in_dir("data").include_type("data").count()
Recursive Traversal
files = (
in_dir("project")
.recursive()
.list()
)
Hidden Files
files = (
in_dir("project")
.recursive()
.show_hidden()
.list()
)
Directory-Only Queries
folders = in_dir().dirs().list()
Include & Exclude Rules
Selectors are monotonic and composable.
include_*narrows the candidate setexclude_*removes matches from the candidate set
files = (
in_dir()
.include_type("image")
.exclude_ext("png")
.list()
)
If a file matches both an include and an exclude filter, it is excluded.
Directory Trees
Generate a nested dictionary representation of the directory structure.
tree = in_dir("src").recursive().tree()
This is a structural view and does not modify the filesystem.
API Reference
in_dir(path=".")
Initializes a DirQuery object for a target directory.
- Validates that the path exists and is a directory
- Defaults to
"."if no path is provided
DirQuery Methods
Selection
.name(pattern)– Sets the glob pattern for discovery (e.g.,"*.py").include_ext(*exts)– Filter to include specific extensions.exclude_ext(*exts)– Filter to exclude specific extensions.include_type(*types)– Filter to include semantic file categories.exclude_type(*types)– Filter to exclude semantic file categories
Traversal
.recursive()– Enables recursive subdirectory traversal.dirs()– Switches the query to match directories instead of files.show_hidden()– Includes items starting with.(hidden files)
Execution
.list()– Executes the query and returnslist[str]of paths.count()– Executes the query and returns the total number of matches.tree()– Executes the query and returns a nested dictionary representing the structure
Supported Semantic Types
| Type | 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 |
Compatibility
- Python: ≥ 3.9
- OS: Platform-independent
- Dependencies: None (standard library only)
License
MIT
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.8.5.tar.gz.
File metadata
- Download URL: fileutils_dir-0.8.5.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8a7f8fee96575a598cc69062a26a6f092689f8d99bd7b1e9b82c35afa4c9f329
|
|
| MD5 |
7a8b4bae80c522902bb57dfdc5d63c82
|
|
| BLAKE2b-256 |
d9dff53b01550b6d2f9e0bee39f4fc7861e72c4553061f27fe346aebb7af9b32
|
File details
Details for the file fileutils_dir-0.8.5-py3-none-any.whl.
File metadata
- Download URL: fileutils_dir-0.8.5-py3-none-any.whl
- Upload date:
- Size: 4.6 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 |
d9ad1dc8517fa6d32e81c9421266a70c4affeeb6bbbf6caaed3f612556ab92eb
|
|
| MD5 |
5d9789a1028f97575e17444bdc52a3cc
|
|
| BLAKE2b-256 |
5b4819d6473856fa4530247a5b7dd6b6ada7c471676339b4b254d1f4075df3be
|