Find files using a simple syntax.
Project description
FileFinder
Find files using a simple syntax.
FileFinder allows to specify the structure of filenames with a simple syntax. Parts of the file structure varying from file to file can be indicated with format strings or regular expressions, or with pre-defined defaults (mainly for dates). Once setup, it can:
- Find corresponding files in a directory
- Parse information from the filenames
- Select only filenames with specific values
- Generate filenames
The package also interface easily with xarray.open_mfdataset
.
Quick examples
The following example will find all files with the structure Data/[month]/Temperature_[depth]_[date].nc
:
finder = Finder('/.../Data', '%(m)/Temperature_%(depth:fmt=d)_%(Y)%(m)%(d).nc')
files = finder.get_files()
We can also select only some files, for instance the first day of each month:
finder.fix_matcher('d', 1)
files = finder.get_files()
We can retrieve values from found files:
filename, matches = finder.files[0]
depth = matches['depth'].get_match()
date = filefinder.library.get_date(matches)
And we can generate a filename with a set of parameters:
finder.get_filename(depth=100, Y=2000, m=1, d=1)
# Specifying the day is optional since we already fixed it to 1.
Requirements
Python >= 3.7.
Installation
From pip:
pip install filefinder
From source:
git clone https://github.com/Descanonge/filefinder.git
cd filefinder
pip install -e .
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
Hashes for filefinder-0.4.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3464bdae2d7e4d74a8865b70fbe8533720413264f3bf1ac69731688768371d89 |
|
MD5 | 6546e6dc1cad11ba2cf357ec24cef819 |
|
BLAKE2b-256 | caaa18e3d2a7e43571b4e6eed658000892c51067dacd785b4b7f62e05adbf171 |