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) ##
自動化解壓文夾壓縮包
import os import datetime import logging import paramiko import tarfile import gzip filename 設定日誌輸出檔案,以天為單位輸出到不同的日誌檔案,以免單個日誌檔案日誌資訊過多,日誌檔案如果不存在則會自動建立,但...
python壓縮與解壓縮
import zipfile import os file dir r d test zip file r d test.zip 建立zip物件 f zip zipfile.zipfile zip file,w zipfile.zip deflated 遍歷要壓縮的目錄 file list os.l...
python壓縮解壓縮 Python 壓縮與解壓縮
python 壓縮與解壓縮 20 aug 2018 python zipfile zip 檔案是常用的壓縮檔案格式。python zipfile模組提供了建立 讀取 寫入 追加等方法來進行zipfile檔案操作。常用zip64擴充套件,最大支援4g。支援解密文件,但是當前不支援建立加密文件,解密速度...