对Python 检查文件名是否规范的实例详解 盗版小说图片

对Python 检查文件名是否规范的实例详解 盗版小说图片

#coding=fileimportsubprocessimportsysimportgetoptrootPath=""nonCheckDirList=[1:]opts,args=([1:],"cs:",["cPath="])foropt,arginopts:ifopt==-c:rootPath=()elifoptin("-s","--cPath"):rootPath=arg#路径字典pathDic={}#新建文件夹(rootdir+/logout)判断指定目录下该文件夹是否存在(rootPath+/logout):(rootPath+/logout)logPath=(rootPath,logout)nonstandard_filename_path=open(logPath+/nonstandard_filename_,w)defGetAllDir(getPath):#print(getPath)paths=(getPath)fordirNameinpaths:dirPath=(getPath,dirName)(dirPath)anddirName!=.svn:#printdirPathrelPath=dirPath[len(rootPath)+1:len(dirPath)]#printrelPathifnotnonCheckDirList.__contains__(relPath):pathDic[relPath]=dirPathGetAllDir(dirPath)defGetAllFile(getPath):files=(getPath)forfileNameinfiles:filePath=(getPath,fileName)(.png)(.PNG):fileName=fileName[0:(.)]firstSign=(r^[a-z0-9_]*$,line1,)iffirstSign:#printfilePath#(r_[\d]*[x|X][\d]*\d)正则表达式(_100x100)sign=(r_[\d]*[x|X][\d]*\d,fileName,|)ifsign:printfileNamenonstandard_filename_(filePath+)else:printfileNamenonstandard_filename_(filePath+)if__name__==__main__:print(main)pathDic[curPath]=rootPathGetAllDir(rootPath)forkeyinpathDic:#printkeyGetAllFile(pathDic[key])添加检查文件重名功能#coding=fileimportsubprocessimportsysimportgetoptnonCheckDirList=[1:]rootPath=()checkRepetPathList=[]ifnonCheckDirList:rootPath=(((),nonCheckDirList[0]))ifnonCheckDirList[0]=="./":rootPath=()for_pathinnonCheckDirList:#--检查重命名路径_cmdRepet=_path[0:2]if_cmdRepet=="/r":repetPath=_path[len(_cmdRepet):len(_path)](repetPath)printrootPath+#路径字典pathDic={}#重名路径字典repetDic={}#新建文件夹(rootdir+/logout)判断指定目录下该文件夹是否存在#(rootPath+/logout):#(rootPath+/logout)#logPath=(rootPath,logout)logPath=()nonstandard_filename_path=open(logPath+"\\"+u"不规范命名文件".encode("GBK")+".txt",w)defGetAllDir(getPath):#print(getPath)paths=(getPath)fordirNameinpaths:dirPath=(getPath,dirName)(dirPath)anddirName!=.svn:#printdirPathrelPath=dirPath[len(rootPath)+1:len(dirPath)]#printrelPathifnotnonCheckDirList.__contains__(relPath):pathDic[relPath]=dirPathGetAllDir(dirPath)defGetAllFile(getPath):files=(getPath)forfileNameinfiles:filePath=(getPath,fileName)(.png)(.PNG):fileName=fileName[0:(.)]firstSign=(r^[a-z0-9_]*$,fileName,)iffirstSign:#printfilePath#(r_[\d]*[x|X][\d]*\d)正则表达式(_100x100)sign=(r_[\d]*[x|X][\d]*\d,fileName,|)ifsign:printfileNamenonstandard_filename_(filePath+)else:printfileNamenonstandard_filename_(filePath+)defCheckRepetFile(getPath):ifcheckRepetPathList:paths=(getPath)fordirNameinpaths:dirPath=(getPath,dirName)(dirPath)anddirName!=.svn:#printdirPathrelPath=dirPath[len(rootPath)+1:len(dirPath)]#printrelPathrepetDic[relPath]=dirPathCheckRepetFile(dirPath)imageList=[]repetImagePath=[]defGetCheckRepetFile(getPath):files=(getPath)forfileNameinfiles:filePath=(getPath,fileName)(.png)(.PNG):#(fileName)(filePath)repet_filename_path=open(logPath+"\\"+u"重复命名文件".encode("GBK")+".txt",w)if__name__==__main__:#print(main)pathDic[curPath]=rootPathGetAllDir(rootPath)forkeyinpathDic:#printkeyGetAllFile(pathDic[key])print+"TheLogoutPath:"+logPath+"\\"+u"不规范命名文件".encode("GBK")+".txt"repetDic[curPath]=rootPath#检查重复文件路径列表for__pathincheckRepetPathList:_repetPath=(rootPath,__path)CheckRepetFile(_repetPath)#遍历路径获得所有图片forkeyinrepetDic:GetCheckRepetFile(repetDic[key])_newImageList=[]forimageinimageList:repetCount=(image)ifrepetCount1:ifnotimagein_newImageList:_(image)forrepetImagein_newImageList:printrepetImagerepet_filename_(repetImage+)forrepetPathPathinrepetImagePath:fileNameName=(repetPathPath)ifrepetImage==fileNameName:repet_filename_(repetPathPath+)#printrepetPathPathprint+"TheLogoutPath:"+logPath+"\\"+u"重复命名文件".encode("GBK")+".txt"。