Skip to content

Instantly share code, notes, and snippets.

@lifefeel
Forked from joonahn/repair_broken_mac_filename.py
Last active October 8, 2019 06:20
Show Gist options
  • Save lifefeel/6789092de9d5fac146698a16f547cdd6 to your computer and use it in GitHub Desktop.
Save lifefeel/6789092de9d5fac146698a16f547cdd6 to your computer and use it in GitHub Desktop.
mac에서 생성한 한글 파일명을 windows에서 읽을 때 깨진 파일을 복구해 주는 스크립트
import sys
from unicodedata import normalize
import glob
import os
def nfd2nfc(data):
return normalize('NFC', data)
if len(sys.argv) > 1:
path = sys.argv[1]
if os.path.isfile(path):
new_filename = nfd2nfc(path)
print(path)
os.rename(path, new_filename)
elif os.path.isdir(path):
diritems = glob.glob(os.path.join(path, '*'))
new_diritems = list(map(lambda x: nfd2nfc(x), diritems))
for src, dst in zip(diritems, new_diritems):
print(src)
os.rename(src, dst)
else:
print('Path Not exist.')
exit()
print('Rename Finished.')
else:
print('Usage : python {} dirname'.format(__file__))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment