Check whether h5 file being written exists. If so, we do not overwrite it because it may be underdoing refinement, changes or updates, for archiving, sharing, or publishing.

This commit is contained in:
2024-11-24 10:38:13 +01:00
parent d10786a534
commit 53fae27472

View File

@@ -162,7 +162,15 @@ def create_hdf5_file_from_filesystem_path(path_to_input_directory: str,
print(start_message) print(start_message)
logging.info(start_message) logging.info(start_message)
# Check if the .h5 file already exists
if os.path.exists(path_to_output_file) and mode in ['w']:
message = (
f"[Notice] The file '{path_to_output_file}' already exists and will not be overwritten.\n"
"If you wish to replace it, please delete the existing file first and rerun the program."
)
print(message)
logging.error(message)
else:
with h5py.File(path_to_output_file, mode=mode, track_order=True) as h5file: with h5py.File(path_to_output_file, mode=mode, track_order=True) as h5file:
number_of_dirs = len(path_to_filenames_dict.keys()) number_of_dirs = len(path_to_filenames_dict.keys())