Skip to content

Commit

Permalink
separate out checks for non-existent file and non-existent dir
Browse files Browse the repository at this point in the history
  • Loading branch information
zm711 authored Jun 20, 2023
1 parent 75e31b9 commit eda5c59
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions neo/io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,12 +452,22 @@ def list_candidate_ios(file_or_folder, ignore_patterns=['*.ini', 'README.txt', '
# to select all files sharing the `session1-` prefix
elif file_or_folder.parent.exists():
filenames = list(file_or_folder.parent.glob(file_or_folder.name + '*'))
# if filenames empty and suffix is provided then non-existent file
# may be written in current dir. So run check for io
if len(filenames)==0 and file_or_folder.suffix:
suffix = file_or_folder.suffix[1:].lower()
if suffix not in io_by_extension:
raise ValueError(f'{suffix} is not a supported format of any IO.')
return io_by_extension[suffix]

# If non-existent file in non-existent dir is given check if this
# structure could be created with an io writing the file
elif file_or_folder.suffix:
suffix = file_or_folder.suffix[1:].lower()
if suffix not in io_by_extension:
raise ValueError(f'{suffix} is not a supported format of any IO.')
return io_by_extension[suffix]

else:
raise ValueError(f'{file_or_folder} does not contain data files of a supported format')

Expand Down

0 comments on commit eda5c59

Please sign in to comment.