import os
def remove_specific_characters(filename, excluded_characters):
path, file = filename.rsplit('\\', 1) if '\\' in filename else ('', filename)
name, extension = os.path.splitext(file)
for char in excluded_characters:
name = name.replace(char, '')
result_filename = name + extension
new_filename = os.path.join(path, result_filename)
os.rename(filename, new_filename)
return new_filename
def remove_specific_characters_in_folder(folder_path, excluded_characters):
for foldername, subfolders, filenames in os.walk(folder_path):
for filename in filenames:
file_path = os.path.join(foldername, filename)
new_file_path = remove_specific_characters(file_path, excluded_characters)
print(f"Renamed: {file_path} -> {new_file_path}")
folder_path = "C:\\Users\\"
excluded_characters = ["【", "】", "[", "]", "(", ")"]
remove_specific_characters_in_folder(folder_path, excluded_characters)