Skip to main content

Small utilities for listing files in directories

Project description

fileutils

PyPi Version License: MIT Python Versions

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.Path and 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 a list[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 .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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fileutils_dir-0.6.1.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

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

fileutils_dir-0.6.1-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file fileutils_dir-0.6.1.tar.gz.

File metadata

  • Download URL: fileutils_dir-0.6.1.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

Hashes for fileutils_dir-0.6.1.tar.gz
Algorithm Hash digest
SHA256 2f0711314d264b0afa71746a5e486b0ad7701053ca210245fc87415c21194cc1
MD5 591b7b3d2b44c30171c04fb27d3ea080
BLAKE2b-256 ac0cb0cf98ba7441903748e27b11a27dae1bcde441a0ae9881a0dfb9ad3e7de0

See more details on using hashes here.

File details

Details for the file fileutils_dir-0.6.1-py3-none-any.whl.

File metadata

  • Download URL: fileutils_dir-0.6.1-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

Hashes for fileutils_dir-0.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d64c0d52c0d369d722e0d01587a1823911ab6c1707ba53321d4c902edd1a4811
MD5 3aa91f9ebf0e4d6f1883f4a230849e45
BLAKE2b-256 00e50dcec15bf3314f94353a4b64b11b71dcc5bf6bbbf10741c9fcca0a4a26e6

See more details on using hashes here.

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