Find files using a simple syntax.
Project description
FileFinder
Find files using a simple syntax.
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
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
File details
Details for the file filefinder-1.1.0.tar.gz
.
File metadata
- Download URL: filefinder-1.1.0.tar.gz
- Upload date:
- Size: 21.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 409328b72e359b4322fe2ade307252ec5084813660ba2ae884721bc5c589a02d |
|
MD5 | b24ec95eb60ead46f257cdf49a160471 |
|
BLAKE2b-256 | b53f41e457ff372d33493e2c48fa4ce08cfc1bfb688db9e84b1bf51a7c95b00e |
File details
Details for the file filefinder-1.1.0-py3-none-any.whl
.
File metadata
- Download URL: filefinder-1.1.0-py3-none-any.whl
- Upload date:
- Size: 22.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 08838990cf876db7596b6b8e4bdb2c21309792a5f02cbcf8805208c7bc9406b2 |
|
MD5 | 266a4bbc67c9e1ed13c99d208eee94fa |
|
BLAKE2b-256 | 0dc6bb6f3c6812c5fbe2ee743cbb20bc5a332e039f429d32152adbaacdb83683 |