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