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, similarly to a regular expression. Once setup, it can:

  • Find corresponding files in a directory (and sub-directories)
  • Parse values from the filenames
  • Select only filenames with specific values or which pass filter functions
  • 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()

Or apply more complicated filters:

finder.fix_by_filters("m", lambda m: m % 2 == 0)

We can retrieve values from found files:

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

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.

Date as a special citizen: the "date" group name is (by default, but this can be deactivated) considered special in some operation, like fixing multiple groups from a datetime object, or having a filter opering on a full date:

finder.fix_group("date", datetime(2018, 2, 1))
finder.fix_by_filter("date", lambda d: d > datetime(2018, 2, 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.3.0.tar.gz (26.8 kB view details)

Uploaded Source

Built Distribution

filefinder-1.3.0-py3-none-any.whl (27.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: filefinder-1.3.0.tar.gz
  • Upload date:
  • Size: 26.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for filefinder-1.3.0.tar.gz
Algorithm Hash digest
SHA256 3ccdbedc5ed342d61c8aa2db4e03033c9edae383ce1880805a71329fccd15e24
MD5 973253b3a3ca3b71f40665e196bf6b44
BLAKE2b-256 faa43a51d6f984a16460881020bee060c147736a2e60e30d0d582050aa628cfe

See more details on using hashes here.

Provenance

The following attestation bundles were made for filefinder-1.3.0.tar.gz:

Publisher: pypi-publish.yml on Descanonge/filefinder

Attestations:

File details

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

File metadata

  • Download URL: filefinder-1.3.0-py3-none-any.whl
  • Upload date:
  • Size: 27.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for filefinder-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 332b5301da509801f5a7f5194bc19c4fd91e4c2b573ff211d1a0b5b17547d16d
MD5 db5916647aabdcb03bafac1aeac8d735
BLAKE2b-256 2c00fe616cc479c23097766576734443317c9e24fa823bae957bd9b85349d775

See more details on using hashes here.

Provenance

The following attestation bundles were made for filefinder-1.3.0-py3-none-any.whl:

Publisher: pypi-publish.yml on Descanonge/filefinder

Attestations:

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