Small utilities for listing files in directories
Project description
fileutils
A minimalist Python library for listing and filtering files with a fluent interface.
Installation
pip install fileutils-dir
Usage
The in_dir function returns a query object, allowing for a fluent and readable way to list or count files.
from fileutils import in_dir
# List all files in the current directory
files = in_dir().list()
# Filter by extension
python_files = in_dir(ext="py").list()
# Filter by predefined categories
media_files = in_dir(dtype=["image", "video"]).list()
# Including hidden files
hidden_and_all = in_dir().show_hidden().list()
# Counting files directly
count = in_dir(path="src", dtype="code").count()
API Reference
in_dir(path=".", *, ext=None, dtype=None)
Creates a DirQuery object.
- path: The directory to search. Accepts
strorpathlib.Path. Defaults to".". - ext: A string or an iterable of file extensions (e.g.,
"py",".py", or["py", "js"]). - dtype: A string or an iterable of predefined file categories (e.g.,
"image", or["text", "pdf"]).
DirQuery Methods
The following methods can be called on the object returned by in_dir():
.list(): Returns alist[str]of file paths matching the criteria..count(): Returns the integer count of matching files..show_hidden(): Sets the query to include hidden files (those starting with a dot). Returns the query object itself for chaining.
Supported Types
The dtype parameter supports the following categories:
| 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
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.4.0.tar.gz.
File metadata
- Download URL: fileutils_dir-0.4.0.tar.gz
- Upload date:
- Size: 3.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0e191e135b04f30b0d8c24507a5efcc63b00ae178966da709a02d02256537cea
|
|
| MD5 |
e26f0b5e636a32c4b34676311ca9c61f
|
|
| BLAKE2b-256 |
f5e0842700ee99f9ae006384173dea4c7da22f1f791bb4f65c4bd9b74115b005
|
File details
Details for the file fileutils_dir-0.4.0-py3-none-any.whl.
File metadata
- Download URL: fileutils_dir-0.4.0-py3-none-any.whl
- Upload date:
- Size: 3.5 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 |
a4b01434739a47c1424e3541c2b4fec5778d5633814e2a75fb707f3c5c89e288
|
|
| MD5 |
dc6fcd3255bf5a44bbd42b653cb5ef81
|
|
| BLAKE2b-256 |
bcf471c72cff6aff79d5875b08f2cc006f44e74331a6370ae58351b2f6a12af5
|