Python/Python for Windows

zipfile을 이용한 특정폴더에 있는 모든 파일 압축

Pydole 2018. 4. 18. 01:18


파이썬 zipfile을 이용한 특정폴더에 있는 모든 파일 압축


 

 from zipfile import *

 import os


 dir = path

 os.chdir(dir)

 

 for file in os.listdir(dir):

     filename = file.rpartition('.') 

        with ZipFile(filename[0]+'.zip', 'w') as compzip:

         compzip.write(file)