Skip to main content

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 str or pathlib.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 a list[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 .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


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.4.0.tar.gz (3.1 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.4.0-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

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

Hashes for fileutils_dir-0.4.0.tar.gz
Algorithm Hash digest
SHA256 0e191e135b04f30b0d8c24507a5efcc63b00ae178966da709a02d02256537cea
MD5 e26f0b5e636a32c4b34676311ca9c61f
BLAKE2b-256 f5e0842700ee99f9ae006384173dea4c7da22f1f791bb4f65c4bd9b74115b005

See more details on using hashes here.

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

Hashes for fileutils_dir-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a4b01434739a47c1424e3541c2b4fec5778d5633814e2a75fb707f3c5c89e288
MD5 dc6fcd3255bf5a44bbd42b653cb5ef81
BLAKE2b-256 bcf471c72cff6aff79d5875b08f2cc006f44e74331a6370ae58351b2f6a12af5

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