利用python解壓zip文件


Python解壓zip文件,性能較低。

#!/usr/bin/python3
import zipfile
import argparse
import sys

def get_parameter():
    parser=argparse.ArgumentParser(description='該腳本用於帶密碼的zip文件')
    parser.add_argument('-f',dest='inputFile',type=str,default='',help='輸入待解壓文件')
    parser.add_argument('-p',dest='passwd',type=str,default='',help='輸入解壓密碼')
    parser.add_argument('-d',dest='dirPath',type=str,default='',help='加壓后的文件保存位置')
    args=parser.parse_args()
    inputFile=args.inputFile
    passwd=args.passwd
    dirPath=args.dirPath
    return inputFile,passwd,dirPath

def main():
    inputFile, passwd,dirPath=get_parameter()
    if inputFile=='':
        print('請輸入待解壓文件')
        sys.exit(1)
    with zipfile.ZipFile(inputFile,'r') as rz:
        rz.extractall(dirPath,pwd=passwd.encode())

if __name__=='__main__':
    main()

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM