Update split_by_size_or_qty_and_compress.py
This commit is contained in:
@@ -13,8 +13,8 @@ files_list = fnmatch.filter((dir),'*.xml')
|
||||
|
||||
def compress(file_names, zip_name):
|
||||
compression = zipfile.ZIP_DEFLATED
|
||||
|
||||
zf = zipfile.ZipFile(zip_name, mode="w")
|
||||
|
||||
try:
|
||||
for file_name in file_names:
|
||||
zf.write(file_name, compress_type=compression)
|
||||
@@ -37,14 +37,14 @@ def split_by_size_or_qty_and_compress(files, size_limit = 1048576, qty_limit = 1
|
||||
file = files.pop()
|
||||
chunk_size += os.path.getsize(file)
|
||||
|
||||
if(chunk_size < size_limit) and (len(chunk) < qty_limit):
|
||||
chunk.append(file)
|
||||
if(chunk_size > size_limit) or (len(chunk) >= qty_limit):
|
||||
compress(chunk, "Part_" + str(part_num) + ".zip")
|
||||
chunk.clear()
|
||||
chunk_size = 0
|
||||
part_num +=1
|
||||
continue
|
||||
|
||||
compress(chunk, "Part_" + str(part_num) + ".zip")
|
||||
chunk.clear()
|
||||
chunk_size = 0
|
||||
part_num +=1
|
||||
chunk.append(file)
|
||||
|
||||
if(len(chunk) > 0):
|
||||
compress(chunk, "Part_" + str(part_num) + ".zip")
|
||||
|
||||
Reference in New Issue
Block a user