Certainly! Below is the cleaned-up version of the script with standard ASCII-only characters — no checkmarks, emojis, or non-standard symbols.
✅ Plain ASCII Python Script (Preview & Confirm File and Directory Renames)
import os
# Mapping of fancy characters to standard ASCII replacements
REPLACEMENTS = {
"'": ["’", "‘", "‚", "‛"],
"-": ["–", "—", "−"]
}
def replace_fancy_chars(name):
"""Replace fancy apostrophes and dashes with standard ASCII characters."""
for standard, fancy_list in REPLACEMENTS.items():
for fancy_char in fancy_list:
name = name.replace(fancy_char, standard)
return name
def collect_directory_renames(root_dir):
"""Collect directory rename operations (from bottom up)."""
proposed_changes = []
for dirpath, dirnames, _ in os.walk(root_dir, topdown=False):
for dirname in dirnames:
old_path = os.path.join(dirpath, dirname)
new_name = replace_fancy_chars(dirname)
new_path = os.path.join(dirpath, new_name)
if old_path != new_path:
proposed_changes.append((old_path, new_path))
return proposed_changes
def collect_file_renames(root_dir):
"""Collect file rename operations."""
proposed_changes = []
for dirpath, _, filenames in os.walk(root_dir):
for filename in filenames:
old_path = os.path.join(dirpath, filename)
new_name = replace_fancy_chars(filename)
new_path = os.path.join(dirpath, new_name)
if old_path != new_path:
proposed_changes.append((old_path, new_path))
return proposed_changes
def show_proposals(changes, label):
if changes:
print("\nProposed {} renames:".format(label))
for old, new in changes:
print(" FROM: {}".format(old))
print(" TO: {}".format(new))
else:
print("\nNo {} renames needed.".format(label))
def get_user_confirmation():
response = input("\nDo you want to proceed with these renames? [y/N]: ").strip().lower()
return response == 'y'
def perform_renames(changes):
for old_path, new_path in changes:
try:
os.rename(old_path, new_path)
except Exception as e:
print("Failed to rename {} -> {}: {}".format(old_path, new_path, e))
def main():
start_dir = os.getcwd()
print("Scanning files and directories under:")
print(" {}".format(start_dir))
# Collect and show proposed renames
dir_changes = collect_directory_renames(start_dir)
show_proposals(dir_changes, "directory")
file_changes = collect_file_renames(start_dir)
show_proposals(file_changes, "file")
# Confirm and rename
if not dir_changes and not file_changes:
print("\nNothing to rename.")
return
if get_user_confirmation():
print("\nRenaming directories...")
perform_renames(dir_changes)
print("Renaming files...")
perform_renames(file_changes)
print("\nRenaming complete.")
else:
print("\nRenaming canceled.")
if __name__ == "__main__":
main()