Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import os, sys
- import unicodedata
- def depthfirstwalk(topdir):
- if not os.path.isdir(topdir):
- yield topdir
- return
- for subpath in os.listdir(topdir):
- fullpath = os.path.join(topdir, subpath)
- if os.path.isdir(fullpath):
- for derived in depthfirstwalk(fullpath):
- yield derived
- yield fullpath
- #os.path.walk(sys.argv[1], fswalk, 1)
- #os.path.walk(sys.argv[1], fswalk, 0)
- for path in depthfirstwalk(sys.argv[1]):
- basename = os.path.basename(path)
- try:
- basename.decode('ascii')
- except UnicodeError:
- try:
- #utfname = name.decode('utf-8').encode('cp949')
- #utfname = name.decode('cp949').encode('utf-8')
- utfname = unicodedata.normalize('NFC', basename.decode('utf-8')).encode('utf-8')
- if utfname != basename:
- dirname = os.path.dirname(path)
- newname = os.path.join(dirname, utfname)
- print newname
- os.rename(path, newname)
- except UnicodeError:
- pass
- # ex: ts=8 sts=4 et
Add Comment
Please, Sign In to add comment