python写的将一些类型的文件压缩为7z格式的脚本

#将一些类型的文件压缩为7z.py
#for folder all file do 7z
import os
import sys
import distutils.file_util

def ImportOkFile():
    if(os.path.isfile("D:\\Records\\将一些类型的文件压缩为7z_record.txt")==False):
        f=open("D:\\Records\\将一些类型的文件压缩为7z_record.txt","w")
        f.close()
    f=open("D:\\Records\\将一些类型的文件压缩为7z_record.txt","r")
    okList=f.readlines()
    f.close()
    doneOkList=[]
    for okFile in okList:
        if(okFile[:3]=="ok "):
            doneOkList.append(okFile[3:-1])
    return doneOkList

def RecordOkFile(file,preinfo="ok "):
    f=open("D:\\Records\\将一些类型的文件压缩为7z_record.txt","a")
    f.write(preinfo+file+"\n")
    f.close()

def OneLayDir(doDir):
    folderfile=os.listdir(doDir)
    if len(folderfile)==1 and os.path.isdir(doDir+"<a href="file:///" +folderfile[0"="" style="color: rgb(102, 153, 0);">\\"+folderfile[0]):
        firstfolder=curfolder=doDir+"\\"+folderfile[0]+"\\"
        folderfile=os.listdir(curfolder)
        while len(folderfile)==1 and os.path.isdir(curfolder+folderfile[0]):
            folderfile=os.listdir(curfolder)
            curfolder=curfolder+folderfile[0]+"\\"
        try:
            folderfile=os.listdir(curfolder)
        except execiption as e:
            return False;
        pathExistPath=[]
        for file in folderfile:
            if os.path.isdir(curfolder+file):
                if os.path.exists(doDir+"<a href="file:///" +file"="" style="color: rgb(102, 153, 0);">\\"+file):
                    os.system("move /y \""+curfolder+file+"\" \""+doDir+"\\"+file+"2\"")
                    pathExistPath.append(doDir+"\\"+file+"2")
                else:
                    os.system("move /y \""+curfolder+file+"\" \""+doDir+"\\"+file+"\"")
            else:
                os.system("move /Y \""+curfolder+file+"\" \""+doDir+"\"")
        os.system("rmdir /S /Q \""+firstfolder+"\"")
        for folder in pathExistPath:
            os.system("move /y \""+folder+"\" \""+folder[:-1]+"\"")
      

阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭