-
-
Save lifefeel/6789092de9d5fac146698a16f547cdd6 to your computer and use it in GitHub Desktop.
mac에서 생성한 한글 파일명을 windows에서 읽을 때 깨진 파일을 복구해 주는 스크립트
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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