refactor: remove dry-run mode and make file renaming the default behavior
This commit is contained in:
parent
657fed1ef0
commit
02dbc12913
|
|
@ -20,14 +20,11 @@ def strip_duplicate_suffix(filename):
|
||||||
def main():
|
def main():
|
||||||
# 1. Check arguments
|
# 1. Check arguments
|
||||||
if len(sys.argv) < 2:
|
if len(sys.argv) < 2:
|
||||||
print("Usage: python strip_suffix.py <path_to_file_or_folder> [more_files...] [--apply]")
|
print("Usage: python strip_suffix.py <path_to_file_or_folder> [more_files...]")
|
||||||
print(" By default, runs in dry-run mode (preview only).")
|
|
||||||
print(" Add --apply to actually rename the files.")
|
|
||||||
return
|
return
|
||||||
|
|
||||||
# 2. Parse arguments
|
# 2. Parse arguments
|
||||||
apply_mode = "--apply" in sys.argv
|
args = [arg.strip(' "\'') for arg in sys.argv[1:]]
|
||||||
args = [arg.strip(' "\'') for arg in sys.argv[1:] if arg != "--apply"]
|
|
||||||
|
|
||||||
target_files = []
|
target_files = []
|
||||||
|
|
||||||
|
|
@ -51,7 +48,6 @@ def main():
|
||||||
rename_count = 0
|
rename_count = 0
|
||||||
skip_count = 0
|
skip_count = 0
|
||||||
|
|
||||||
print(f"Mode: {'APPLY (will rename files)' if apply_mode else 'DRY-RUN (preview only)'}")
|
|
||||||
print("-" * 50)
|
print("-" * 50)
|
||||||
|
|
||||||
for filepath in target_files:
|
for filepath in target_files:
|
||||||
|
|
@ -68,21 +64,15 @@ def main():
|
||||||
skip_count += 1
|
skip_count += 1
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if apply_mode:
|
|
||||||
os.rename(filepath, clean_path)
|
os.rename(filepath, clean_path)
|
||||||
print(f" RENAMED: '{filename}' -> '{clean_name}'")
|
print(f" RENAMED: '{filename}' -> '{clean_name}'")
|
||||||
else:
|
|
||||||
print(f" WOULD RENAME: '{filename}' -> '{clean_name}'")
|
|
||||||
rename_count += 1
|
rename_count += 1
|
||||||
|
|
||||||
print("-" * 50)
|
print("-" * 50)
|
||||||
if rename_count == 0:
|
if rename_count == 0:
|
||||||
print("No files with duplicate suffixes found.")
|
print("No files with duplicate suffixes found.")
|
||||||
else:
|
else:
|
||||||
action = "Renamed" if apply_mode else "Would rename"
|
print(f"Renamed {rename_count} file(s). Skipped {skip_count} file(s).")
|
||||||
print(f"{action} {rename_count} file(s). Skipped {skip_count} file(s).")
|
|
||||||
if not apply_mode:
|
|
||||||
print("\nRun again with --apply to actually rename the files.")
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue