calamari.catalog.find_files#
- calamari.catalog.find_files(root, *, skip_dirs=('.git',), path_filter=None)#
Walk
rootrecursively and return files recognised by a registeredcalamari.ioloader, in sorted path order.The signature check (
sniff_format()) is cheap (reads only the first ~40 lines) so this is safe to run over large trees; it also never raises on an unreadable file (permission or encoding errors are treated as “not a match” by the loader registry).Open the root before walking it, so a missing or unreadable root raises the operating system’s
OSErrorrather than resembling an empty directory. Filesystem exceptions retain their original types (IO-5).A subdirectory that cannot be listed does not abort the walk: one locked folder deep in a shared tree should not cost the inventory of everything else. It is not skipped silently either – files inside it are missing from the result, and a catalog quietly short of a whole run folder is exactly the failure nobody notices – so a single
UserWarningafter the walk names every such directory and theskip_dirs=that leaves it out knowingly.- Parameters:
root (
Path|str) – Root directory to scan. Relative paths resolve against the current working directory, as for any file operation.skip_dirs (
tuple[str,...]) – Directory names pruned from the walk wherever encountered (not just at the top level) – e.g. version-control metadata directories that may themselves contain look-alike files. Defaults to('.git',). A pruned directory is never listed, so naming an unreadable one here also silences its warning.path_filter (
Callable[[Path],bool] |None) – Predicate receiving each file’s path relative toroot. False excludes the file before any content probe or read. Use only path information for cheap filtering; a filename rule cannot establish scientific file role. Directories are still listed (useskip_dirsto prune them). Exceptions from the predicate propagate to the caller. Default None: probe every candidate.
- Return type:
- Returns:
list[Path]– Paths of files whose content matches a registered loader’s signature, sorted by path component (each component compared as a plain, case-sensitive string). The order is a property of the names alone, so it is the same on every machine:os.walk()yields directory-listing order, which the filesystem chooses and which is not alphabetical even on one machine, and a result indexed by position –paths[0]– would otherwise mean a different file on each. Comparing component by component keeps each directory’s contents together (run/b.datsorts beforerun-2/a.dat, although'-' < '/'in a flat string sort). The sort is deliberately not “natural”:chi_10K.datsorts beforechi_2K.dat, because reading physics into a filename is a guess. Sort the measurements themselves (the*_familyplot helpers order curves by their measured fixed value) when order matters.- Raises:
FileNotFoundError – If
rootdoes not exist.NotADirectoryError – If
rootexists but is not a directory (a single file is not a tree to search – pass it tocalamari.io.load()directly).PermissionError – If
rootexists but cannot be listed.
- Warns:
UserWarning – If one or more subdirectories below
rootcannot be listed; they are left out and the walk continues.