Created
June 20, 2024 05:56
-
-
Save iolo/377c5219b1c25fec5690d613c34d96bf to your computer and use it in GitHub Desktop.
맥에서 만들어져서 풀어쓰기(NFD) 파일 이름을 모아쓰기(NFC) 파일 이름으로 변경(python버전)
This file contains hidden or 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 os | |
import sys | |
import unicodedata | |
def scan_files(base_dir, recursive=True, dry_run=True): | |
for (root, dirs, files) in os.walk(base_dir): | |
for f in files: | |
new_name = unicodedata.normalize('NFC', f); | |
if new_name != f: | |
print(f'{root}/{f} -> {new_name}') | |
if not dry_run: | |
os.rename(os.path.join(root, f), os.path.join(root, new_name)) | |
if recursive: | |
for d in dirs: | |
scan_files(os.path.join(root, d), True, dry_run); | |
if __name__ == '__main__': | |
base_dir = next((arg for arg in sys.argv[1:] if not arg.startswith('-')), '.') | |
recursive = '-r' in sys.argv or '--recursive' in sys.argv | |
dry_run = '-n' in sys.argv or '--dry-run' in sys.argv | |
scan_files(base_dir, recursive, dry_run) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment