개발/Python
Python(파이썬)으로 7z 한번에 압축하기
모아이모아이
2016. 11. 13. 21:51
# 사용방법 : 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")