Skip to content

Commit 84d10d7

Browse files
committed
use ignore pattern instead of ignore suffix for more flexibility (e.g. for README files)
1 parent faf073e commit 84d10d7

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

neo/io/__init__.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -410,16 +410,17 @@ def get_io(file_or_folder, *args, **kwargs):
410410
raise IOError(f"Could not identify IO for {file_or_folder}")
411411

412412

413-
def list_candidate_ios(file_or_folder, ignore_suffix=['ini']):
413+
def list_candidate_ios(file_or_folder, ignore_patterns=['*.ini', 'README.txt', 'README.md']):
414414
"""
415415
Identify neo IO that can potentially load data in the file or folder
416416
417417
Parameters
418418
----------
419419
file_or_folder (str, pathlib.Path)
420420
Path to the file or folder to load
421-
ignore_suffix (list)
422-
List of suffixes to ignore when scanning for known formats. Default: ['ini']
421+
ignore_patterns (list)
422+
List of patterns to ignore when scanning for known formats. See pathlib.PurePath.match().
423+
Default: ['ini']
423424
424425
Returns
425426
-------
@@ -438,14 +439,14 @@ def list_candidate_ios(file_or_folder, ignore_suffix=['ini']):
438439
# scan files in folder to determine io type
439440
filenames = [f for f in file_or_folder.glob('*') if f.is_file()]
440441
# keep only relevant filenames
441-
filenames = [f for f in filenames if f.suffix and f.suffix[1:].lower() not in ignore_suffix]
442+
filenames = [f for f in filenames if f.suffix and not any([f.match(p) for p in ignore_patterns])]
442443

443444
# if no files are found in the folder, check subfolders
444445
# this is necessary for nested-folder based formats like spikeglx
445446
if not filenames:
446447
filenames = [f for f in file_or_folder.glob('**/*') if f.is_file()]
447448
# keep only relevant filenames
448-
filenames = [f for f in filenames if f.suffix and f.suffix[1:].lower() not in ignore_suffix]
449+
filenames = [f for f in filenames if f.suffix and not any([f.match(p) for p in ignore_patterns])]
449450

450451
# if only file prefix was provided, e.g /mydatafolder/session1-
451452
# to select all files sharing the `session1-` prefix

0 commit comments

Comments
 (0)