2016-12-08 17:15:56 +00:00
|
|
|
from sys import argv
|
|
|
|
from unidecode import unidecode
|
2016-12-20 13:22:44 +00:00
|
|
|
from os import rename
|
|
|
|
from os.path import basename, dirname
|
|
|
|
from os.path import join as joinpath
|
2016-12-08 17:15:56 +00:00
|
|
|
|
|
|
|
|
2016-12-14 15:45:12 +00:00
|
|
|
# whitespaces will be replaced
|
|
|
|
# dots are ok
|
|
|
|
# do not ruin previous work
|
|
|
|
# dashes are ok
|
|
|
|
whitelist = [' ', '.', '_', '-']
|
|
|
|
|
2016-12-20 13:22:44 +00:00
|
|
|
for path in argv[1:]:
|
|
|
|
dir = dirname(path)
|
|
|
|
file = basename(path)
|
|
|
|
rename(path,
|
2016-12-08 17:15:56 +00:00
|
|
|
unidecode
|
|
|
|
(
|
2016-12-20 13:22:44 +00:00
|
|
|
joinpath
|
|
|
|
(
|
|
|
|
dir,
|
2017-02-13 14:50:11 +00:00
|
|
|
''.join(ch for ch in file.replace(' ', '_')
|
2016-12-20 13:22:44 +00:00
|
|
|
if ch.isalnum()
|
|
|
|
or ch in whitelist)
|
|
|
|
)
|
2017-02-13 14:50:11 +00:00
|
|
|
))
|