Код: Выделить всё
^CTraceback (most recent call last):
File "~/normalize_filepaths.py", line 2
for root, dirs, files in os.walk(target, topdown = False):
File "", line 377, in walk
KeyboardInterrupt
Код: Выделить всё
def normalize(fp):
"""
>>> normalize("/Volumes/MM_BUP/MIGUEL/Acólitos")
'/Volumes/MM_BUP/MIGUEL/Acolitos'
>>> normalize("/Volumes/MM_BUP/MIGUEL/Acólitos")
'/Volumes/MM_BUP/MIGUEL/Acolitos'
>>> normalize("'This is my cup.' _ ゼロコ ZEROKO _ 紅茶の遊び方 _ mime _ clowning-8MgRJAXn1tE.mp4")
"'This is my cup.' _ ZEROKO _ _ mime _ clowning-8MgRJAXn1tE.mp4"
>>> normalize(" großer Tag")
' grosser Tag'
"""
fp = fp.replace("ß", "ss")
name_clean = unicodedata.normalize('NFD', fp)
return name_clean.encode('ascii', 'ignore').decode("ascii")
def main(target="/some/path"):
for root, dirs, files in os.walk(target, topdown = False):
for name in files + dirs:
filepath = os.path.join(root, name)
clean = normalize(name)
new_filepath = os.path.join(root, clean)
shutil.move(filepath, new_filepath)
Подробнее здесь: https://stackoverflow.com/questions/792 ... rnal-drive
Мобильная версия