Skip to content

Support wildcards in file-tree `get` and `get_mult`

Support glob-like syntax.

It will be an optional flag when loading the file-tree (i.e., FileTree.read(..., glob=True). When set, file-tree will have the following behaviour:

  • For templates not containing any wildcards (* or ?), simply return the path.
  • For templates containing wildcards, use the python glob package to find any matches for any * in the filename. An error is raised if there are no matches or more than one match. The one and only match is returned.
    • It will be possible to override this default behaviour of raising an error for no or multiple matches by providing your own selector. For example, FileTree.read(..., glob=lambda filenames: filenames[-1]) will return the last match if there are multiple ones.

Wildcards can be written into the template directly, such as in:

sub-{subject}
    T1w_*.nii.gz

This assumes that for each subject ID there is one NIFTI file starting with "T1w_".

Alternatively, wildcards can be included in placeholder values:

some_text=*

sub-{subject}
    T1w_{some_text}.nii.gz

Both of these will have the same behaviour.

Implementation details

This will affect:

  • get
  • get_mult
  • update_glob
Edited by Michiel Cottaar