Skip to content

Commit eda5c59

Browse files
authored
separate out checks for non-existent file and non-existent dir
1 parent 75e31b9 commit eda5c59

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

neo/io/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,12 +452,22 @@ def list_candidate_ios(file_or_folder, ignore_patterns=['*.ini', 'README.txt', '
452452
# to select all files sharing the `session1-` prefix
453453
elif file_or_folder.parent.exists():
454454
filenames = list(file_or_folder.parent.glob(file_or_folder.name + '*'))
455+
# if filenames empty and suffix is provided then non-existent file
456+
# may be written in current dir. So run check for io
455457
if len(filenames)==0 and file_or_folder.suffix:
456458
suffix = file_or_folder.suffix[1:].lower()
457459
if suffix not in io_by_extension:
458460
raise ValueError(f'{suffix} is not a supported format of any IO.')
459461
return io_by_extension[suffix]
460462

463+
# If non-existent file in non-existent dir is given check if this
464+
# structure could be created with an io writing the file
465+
elif file_or_folder.suffix:
466+
suffix = file_or_folder.suffix[1:].lower()
467+
if suffix not in io_by_extension:
468+
raise ValueError(f'{suffix} is not a supported format of any IO.')
469+
return io_by_extension[suffix]
470+
461471
else:
462472
raise ValueError(f'{file_or_folder} does not contain data files of a supported format')
463473

0 commit comments

Comments
 (0)