Skip to main content

Find files using a simple syntax.

Project description

FileFinder

Find files using a simple syntax.

PyPI GitHub release codecov test status Documentation Status

FileFinder allows to specify the structure of filenames using a simple syntax. Parts of the file structure varying from file to file are indicated within named groups, either with format strings or regular expressions (with some pre-defined values for some names). Once setup, it can:

  • Find corresponding files in a directory (and sub-directories)
  • Parse values from the filenames
  • Select only filenames with specific values
  • Generate filenames

Quick examples

The following example will find all files with the structure Data/param_[parameter]/[year]/Temperature_[date].nc:

finder = Finder('/.../Data', 'param_%(parameter:fmt=.1f)/%(Y)/Temperature_%(Y)%(m)%(d).nc')
files = finder.get_files()

We can also select only some files, for instance only in january:

finder.fix_group('m', 1)
files = finder.get_files()

We can retrieve values from found files:

filename, matches = finder.files[0]
parameter = matches["parameter"]
# the date as a datetime object
date = filefinder.library.get_date(matches)

And we can generate a filename with a set of parameters:

finder.make_filename(parameter=0.5, Y=2000, m=1, d=1)
# Specifying the month is optional since we already fixed it to 1.

Requirements

Python >= 3.10

Installation

From pip:

pip install filefinder

From source:

git clone https://github.com/Descanonge/filefinder.git
cd filefinder
pip install -e .

or

pip install -e https://github.com/Descanonge/filefinder.git#egg=filefinder

Documentation

Documentation is available at filefinder.readthedocs.io.

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

filefinder-1.2.0.tar.gz (22.0 kB view details)

Uploaded Source

Built Distribution

filefinder-1.2.0-py3-none-any.whl (22.1 kB view details)

Uploaded Python 3

File details

Details for the file filefinder-1.2.0.tar.gz.

File metadata

  • Download URL: filefinder-1.2.0.tar.gz
  • Upload date:
  • Size: 22.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for filefinder-1.2.0.tar.gz
Algorithm Hash digest
SHA256 81236a1403cc6c06737e8ad11b096dfac8e76b5eadde2ccafe1c15c423a7629c
MD5 749a5a997aa20bceadd6d4e667f5a559
BLAKE2b-256 54fb0b5382b7fdf36aa30dae623976768cbed0b92c0560f677ec26e65ab3d7a5

See more details on using hashes here.

File details

Details for the file filefinder-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: filefinder-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 22.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for filefinder-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 862a1fec274027804ebfff1b79c3834968206e1b3865a765d72471908858c8e5
MD5 89c129a2011ce9b7375f5c82be9aae7d
BLAKE2b-256 6f8419fc290eb54ef07885c9665216b69a83c0b2b0f5765415273f32a20e40be

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page