Last active
November 5, 2021 21:41
-
-
Save Mr-Z-2697/0cf9ee456651ca272b390e9fbf25e716 to your computer and use it in GitHub Desktop.
repair filename decoded by incorrect codepage
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,sys | |
import pathlib | |
def ren(x,dryrun): | |
oripath=pathlib.Path(x).absolute() | |
oriname=oripath.name | |
modname=oriname.encode('cp936').decode('cp932') | |
modpath='\\'.join(str(oripath).split('\\')[:-1]+[modname]) # for windows, this should be modified to work on linux | |
if not dryrun: | |
os.rename(oripath,modpath) | |
else: | |
print('rename \"%s\" to \"%s\"\n'%(oripath,modpath)) | |
for x in sys.argv[1:]: | |
ren(x,True) | |
ex=int(input('\nfile will be renamed according to above, execute? (1/0): ')) | |
if ex: | |
for x in sys.argv[1:]: | |
ren(x,False) | |
input('%s, enter to exit'%('complete' if ex else 'done nothing')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment