from pathlib import Path special_chars = ('<', '>', ':', '"', '/', '\\', '|', '?', '*', '/') def replace_all(text, items): for i in items: text = text.replace(i, '') return text print('WARNING: Scaning large directories trees may take a lot of time.') for file in Path('.').glob('**/*'): if any(map(lambda char: char in file.name, special_chars)): new_name = replace_all(file.name, special_chars) print(f'Old name: {file}') print(f'New name: {file.with_name(new_name)}') print() file.rename(file.with_name(new_name))