From 22a13b829e1762974906ac92216af7eb6a29eba1 Mon Sep 17 00:00:00 2001 From: Moritz Gerster <45031224+moritz-gerster@users.noreply.github.com> Date: Mon, 21 Nov 2022 06:47:21 +0100 Subject: [PATCH] Enable matching json files https://github.com/mne-tools/mne-bids/issues/1098#issuecomment-1321068649 --- mne_bids/path.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/mne_bids/path.py b/mne_bids/path.py index cd984372e..3de9af317 100644 --- a/mne_bids/path.py +++ b/mne_bids/path.py @@ -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 @@ -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)