맥에서 사용하던 폴더나 파일을 윈도우로 가져오면 자음과 모음이 분리된다. 일명 자소분리라고 한다.
인터넷에서 다시 원래 이름으로 자음과 모음을 붙여 한 글자로 만들어주는 프로그램이 많이 있다. 그중 괜챦은 프로그램은 HangulJasoFixer2.exe 파일이다.
하지만, 파이썬으로도 간단하게 변환할 수 있다.
import os import unicodedata type = 'NFC' stack = [] def findfile(path): for dirpath, dirname, filename in os.walk(path): for name in dirname: convertname = unicodedata.normalize(type, name) if convertname != name: #print(os.path.join(dirpath, name) + " -> " + os.path.join(dirpath, convertname)) stack.append([os.path.join(dirpath, name), os.path.join(dirpath, convertname)]) for name in filename: convertname = unicodedata.normalize(type, name) if convertname != name: #print(os.path.join(dirpath, name) + " -> " + os.path.join(dirpath, convertname)) stack.append([os.path.join(dirpath, name), os.path.join(dirpath, convertname)]) def renamefile(): print("result:") for k in range(len(stack)): files = stack.pop() print(files[0] + " --> " + files[1]) os.rename(files[0], files[1]) findfile("c:\\temp") renamefile()
위의 예제는 c:\temp 폴더 하위에 있는 모든 폴더나 파일의 자소변환을 해주는 것이다.