{{{ # 파일 명을 받아서 압축해 주는 스크립트 # ver : 2016.11.23.a import os import sys import glob import zipfile _20MB = 20*1024*1024 MAX_FILE_SIZE = 100*1024*1024 def compressWithSize(files, max_size): file_number = len(files) file_count = 0; target_file = files[1]; isNewFile = False filesize = 0 print (target_file) target = zipfile.ZipFile(target_file+".zip", 'w') for idx in range (2, file_number): all_flist = glob.glob (files[idx]) for f in all_flist: if os.path.isdir(f): pass tmpfilesize = os.path.getsize(f) if tmpfilesize >= MAX_FILE_SIZE: print ("Ignore " + f) pass if filesize+tmpfilesize >= max_size and isNewFile == False: target.close() isNewFile = True if isNewFile == True: target = zipfile.ZipFile(target_file+str(file_count)+".zip", 'w') isNewFile = False file_count = file_count+1 filesize = 0 target.write(f) filesize = filesize + tmpfilesize target.close() #------------------------------------------------------------------------------- # main if __name__ == "__main__": if len(sys.argv) < 3: print ("Usage : pyzip source1 [source2]*") else: compressWithSize(sys.argv, _20MB) }}}