Python 自动化 解压缩

import subprocess
import zipfile as zf
import platform as pf
import os

class ZipObj():
    def __init__(self, filepathname, passwd,tip_path):
        self.filepathname = filepathname    #文件名
        self.passwd = passwd        #压缩密码
        self.Tip_Path = tip_path   #注释

    def enCrypt(self, deleteSource=False):
    # """
    #     压缩加密,并删除原数据
    #     window系统调用rar程序
    #
    #     linux等其他系统调用内置命令 zip -P123 tar source
    #     默认不删除原文件
    # """
        target = "b.zip"
        source = self.filepathname
        if pf.system() == "Windows":

            # rar a -p"www.hanxinkong.top"  filename.zip D:/360MoveData/Users/Administrator/Desktop/test/*
            # rar  a -ep1 -p"www.hanxinkong.top" test.zip - z"D:\360MoveData\Users\Administrator\Desktop\Tip.txt"   D:/360MoveData/Users/Administrator/Desktop/test/*
            # ep1 排除上级(基本)目录
            
            cmd = ['rar','a', '-p"%s"' % (self.passwd), target, source]
            cmd_tip = ['rar', 'c', 'z"%s"' % (self.Tip_Path), target]
            print (cmd)
            p = subprocess.Popen(cmd, executable=r'D:\COMMOND SAFE\winrar\WinRAR.exe')
            p.wait()

            # rar c z"D:/360MoveData/Users/Administrator/Desktop/Tip.txt"  filename
            t = subprocess.Popen(cmd, executable=r'D:\COMMOND SAFE\winrar\WinRAR.exe')
            t.wait()

        else:
            cmd = ['zip', '-P %s' % self.passwd, target, source]
            p = subprocess.Popen(cmd)
            p.wait()
        #            os.system(" ".join(cmd))
        if deleteSource:
            os.remove(source)

if __name__ == "__main__":
    filepathname = "D:/360MoveData/Users/Administrator/Desktop/test/*"
    passwd = "www.hanxinkong.top"
    tip_path = "D:/360MoveData/Users/Administrator/Desktop/Tip.txt"

    zipo = ZipObj(filepathname,passwd,tip_path)

    zipo.enCrypt(deleteSource=False) ##

你可能感兴趣的:(python)