Skip to content

Commit

Permalink
Enable matching json files
Browse files Browse the repository at this point in the history
  • Loading branch information
moritz-gerster committed Nov 21, 2022
1 parent 1b04da8 commit 22a13b8
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions mne_bids/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ def update(self, *, check=None, **kwargs):
raise e
return self

def match(self, check=False):
def match(self, ignore_json=True, check=False):
"""Get a list of all matching paths in the root directory.
Performs a recursive search, starting in ``.root`` (if set), based on
Expand All @@ -814,17 +814,22 @@ def match(self, check=False):
'BIDS root directory path to `root` via '
'BIDSPath.update().')

# allow searching by datatype
# all other entities are filtered below
# Allow searching by datatype because datatype is only present in the
# bids_path but not in the file name "bids_path.basename".
# All other entities are filtered below
if self.datatype is not None:
search_str = f'*/{self.datatype}/*'
else:
search_str = '*.*'

paths = self.root.rglob(search_str)
# Only keep files (not directories), and omit the JSON sidecars.
paths = [p for p in paths
if p.is_file() and p.suffix != '.json']
# Only keep files (not directories), and omit the JSON sidecars
# if ignore_json is True.
if ignore_json:
paths = [p for p in paths
if p.is_file() and p.suffix != '.json']
else:
paths = [p for p in paths if p.is_file()]
fnames = _filter_fnames(paths, suffix=self.suffix,
extension=self.extension,
**self.entities)
Expand Down

0 comments on commit 22a13b8

Please sign in to comment.