from sys import argv from unidecode import unidecode from os import rename from os.path import basename, dirname from os.path import join as joinpath # whitespaces will be replaced # dots are ok # do not ruin previous work # dashes are ok whitelist = (' ', '.', '_', '-') for path in argv[1:]: dir = dirname(path) file = basename(path) rename(path, unidecode ( joinpath ( dir, ''.join(ch for ch in file.replace(' ', '_') if ch.isalnum() or ch in whitelist) ) ))