Skip to content

Commit dc6dbce

Browse files
committed
[#9] Remove before rename.
1 parent 3e68c90 commit dc6dbce

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

publish_netcdf.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,17 @@ def replace_spaces_in_names(path):
7373
for root, dirs, files in walk:
7474
for f in files:
7575
if " " in f:
76-
os.rename(os.path.join(root, f), os.path.join(root, f.replace(" ", "__")))
76+
replacement = os.path.join(root, f.replace(" ", "__"))
77+
if pathlib.Path(replacement).exists():
78+
os.remove(replacement)
79+
os.rename(os.path.join(root, f), replacement)
7780
replaced += 1
7881
for d in dirs:
7982
if " " in d:
80-
os.rename(os.path.join(root, d), os.path.join(root, d.replace(" ", "__")))
83+
replacement = os.path.join(root, d.replace(" ", "__"))
84+
if pathlib.Path(replacement).exists():
85+
shutil.rmtree(replacement)
86+
os.rename(os.path.join(root, d), replacement)
8187
replaced += 1
8288
if replaced:
8389
logger.warning(f"Replaced {replaced} name{'s' if replaced != 1 else ''} " \

0 commit comments

Comments
 (0)