mathause / filefinder

find and parse file and folder names
MIT License
3 stars 1 forks source link

use format specifiers to create names #91

Open mathause opened 4 months ago

mathause commented 4 months ago

Format specifiers are not taken into account when creating names:

import filefinder

f = filefinder.FileFinder(
    path_pattern="",
    file_pattern="domain_{domain:02d}.nc",
)

domain = 1

print(f.create_full_name(domain=domain))
print(f"domain_{domain:02d}.nc")
domain_1.nc
domain_01.nc

Because the _pattern_no_fmt_spec is used:

https://github.com/mathause/filefinder/blob/729c8eeddab6f37c989f5af3d2750f64b4638b65/filefinder/_filefinder.py#L52

In this case it would be good if the fmt spec was used. But does that hold in general?

mathause commented 4 months ago

There are specifier that parse can parse but that are not valid format options (e.g. "{char:l}". See