自动命名Python脚本 - Hoblovski's Blog - 想拿Ag的蒟蒻.已经Ag滚出.
匈牙利算法的优化
RSA加密算法

自动命名Python脚本

Hoblovski posted @ 2014年8月09日 03:18 in Discussion with tags python , 804 阅读

...退役了只好学学Python...

替换下载后的编码错误

比如 "%28C81%29 %5BKAROMIX %28karory%29%5D ....."

现在改用了一种更好的代码风格

#PROGRAM RENAMER;
import os;

Dict={
        '%5B':'[',      '%5b':'[',
        '%5D':']',      '%5d':']',
        '%28':'(',      '%29':')',
        '%26':'&',      '%2B':'+',
}

CurDir=os.getcwd()+'//';
FileList=os.listdir(CurDir);
LogFile=open('Rename.log','w');
print>>LogFile, 'Renaming Work Log';
print>>LogFile, '';
for Name in FileList:
        NewName=Name;
        for i in Dict:NewName=NewName.replace(i,Dict[i]);
        if Name!=NewName:
                print>>LogFile, 'Original: ',Name;
                print>>LogFile, 'Current:  ',NewName;
                print>>LogFile, '';
                os.rename(CurDir+Name,CurDir+NewName);
print 'Successful Renaming work. Press Any Key to Exit';
os.system('pause>nul');
exit();

批量加前缀和后缀

#PROGRAM RENAMER;
import os;

Prefix='[CASO&Sumisora][Gochiusa][';
Suffix='][GB][720p]';
CurDir=os.getcwd()+'//';
FileList=os.listdir(CurDir);
for Name in FileList:
        NewName=Prefix+Name;
        for i in reversed(range(len(NewName))):
                if NewName[i]=='.':
                        NewName=NewName[0:i]+Suffix+NewName[i:len(NewName)];
                        break;
        else:
                NewName=NewName+Suffix;
        os.rename(CurDir+Name,CurDir+NewName);
print 'Successful Renaming work. Press Any Key to Exit';
os.system('pause>nul');
exit();

登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter