Created
May 1, 2018 13:52
-
-
Save Inori/3dd0ddb0f6ee4ea6b07c42b0546e8d91 to your computer and use it in GitHub Desktop.
Rename wrong jis codec file
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 os | |
import sys | |
def jis_rename(root): | |
for root,dirs,files in os.walk(root): | |
for file in files: | |
file = os.path.join(root, file) | |
d = os.path.dirname(file) | |
f = os.path.basename(file) | |
f = f.encode('gbk').decode('sjis') | |
os.renames(file, os.path.join(d, f)) | |
for dir in dirs: | |
dir = os.path.join(root, dir) | |
jis_rename(dir) | |
d = os.path.dirname(dir) | |
f = os.path.basename(dir) | |
f = f.encode('gbk').decode('sjis') | |
os.renames(dir, os.path.join(d, f)) | |
break | |
def main(): | |
if len(sys.argv) != 2: | |
print('Please input folder name.') | |
exit(0) | |
folder = sys.argv[1] | |
if not folder: | |
print('Please input folder name.') | |
exit(0) | |
jis_rename(folder) | |
new_folder = folder.encode('gbk').decode('sjis') | |
os.renames(folder, new_folder) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment