본문 바로가기

개발/Python

Python(파이썬)으로 7z 한번에 압축하기

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# 사용방법 :  fielist.txt 파일에 쉼표를 구분자로 폴더이름,파일이름 작성
# 사용 예 : 2016-11-13,압축할파일
# 사용 결과 : 2016-11-13폴더에 압축할파일.7z로 파일이 만들어짐
#
 
# -*- coding: utf8 -*-
  
import zipfile
import os
 
 
zipPassword = "압축암호"
with open('fielist.txt') as f:
        lines = f.readlines()
        for line  in lines :
            lineArray = line.split(',')
            folderName = lineArray[0]
            hashValue = lineArray[1].replace("\n","")
 
            if not os.path.exists("./" + folderName):
                os.makedirs("./" + folderName)
 
            #compression_level = 5 # 1-9
            if not os.path.exists("./Temp"):
                os.makedirs("./Temp")
 
            os.system("move " + hashValue + " ./Temp/" + hashValue)
            command = "7za.exe a -scsUTF-8 -mx3 -t7z -r -y -mhe -bd -p" + zipPassword + " "  + "./" + folderName + "/" + hashValue + ".7z ./Temp/*"
            os.system(command)
            os.system("del /Q Temp")