diff --git a/scripts/filename_replace.py b/scripts/filename_replace.py index 1e9e932..5a648a7 100644 --- a/scripts/filename_replace.py +++ b/scripts/filename_replace.py @@ -60,7 +60,7 @@ def get_replace_list(opt): def rename_files(opt): find_list = get_replace_list(opt) - for file in glob.glob(opt.img_dir + "/*"): + for idx, file in glob.iglob(opt.img_dir + "/*"): print(file) if os.path.splitext(file)[1] in (".jpg", ".png", ".jpeg", ".gif", ".bmp", ".webp"): @@ -74,8 +74,9 @@ def rename_files(opt): try: print(f"Renaming {file} to {new_filename}") if os.path.exists(new_filename): - print(f"filename already exists, cannot rename:{file} to {new_filename}") - else: + new_filename = new_filename + "_" + idx + print(f"filename already exists, appended '_n' to {new_filename}") + try: os.rename(file, new_filename) except Exception as e: