I am writing a script currently to write 1hr-data into 4 files with the same name(i.e., timestamp). When I do not zip them File1: 1609306077 and File2: 1609309671. When the Zip function is not applied, the files are written individually and everything looks great.
Data_zip = zipfile.ZipFile('location' + str(timestamp) + '.zip', 'w')
for folder, subfolders, files in os.walk('location'):
for file in files:
if file.startswith(str(timestamp)):
Data_zip.write(os.path.join(folder, file), os.path.relpath(os.path.join(folder,file), 'location'), compress_type = zipfile.ZIP_DEFLATED)
Data_zip.close()
Once this code is being used. The files are like File1 contains the file2, file3 and so on. I realise the problem is one of the files is not closing. I'd also tried file.close() and it does not work. Is there any other efficient method to zip the files? or can I forcibly close the file using Python?