filefisher.FileFinder.find_files#
- FileFinder.find_files(keys=None, *, on_parse_error='raise', on_empty='raise', **keys_kwargs)#
find files in the file system using the file pattern
- Parameters:
keys (dict) – Dictionary containing keys to create the search pattern. Several names can be passed for each key as list (interpreted as or). None is ignored.
on_parse_error (“raise” | “warn” | “skip”, default: “raise”) – What to do if a path/file name cannot be parsed. If “raise” raises a ValueError, if “warn” raises a warning and if “skip” ignores the file.
on_empty (“raise” | “warn” | “allow”, default: “raise”) – Behaviour when no files are found: “raise” (default) raises a ValueError, “warn” raises a warning. For “warn” and “allow” an empty FileContainer is returned.
**keys_kwargs ({key: indexer, …}, optional) – The keyword arguments form of
keys. When the same key is passed inkeysandkeys_kwargsthe latter takes priority.
Notes
Missing
keysare replaced with"*".Examples
>>> path_pattern = "/root/{category}" >>> file_pattern = "{category}_file_{number}" >>> ff = FileFinder(path_pattern, file_pattern)
>>> ff.find_files() Looks for - "/root/*/*_file_*"
>>> ff.find_files(number=[1, 2]) Looks for - "/root/*/*_file_1" - "/root/*/*_file_2"
>>> meta = {"category": "foo", "number": [1, 2]} >>> ff.find_files(meta, category="bar") Looks for - "/root/bar/bar_file_1" - "/root/bar/bar_file_2"