Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.
Originally posted by: dkhuon@gogoair.comI am modifying someone code to zip multiple file to a single zip file. THe code works, however the output stream got more rows than the input:
For instance, I have file1.csv, file2.csv, file3.csv. It creates a filez.zip containing just those 3 files. However, file1.csv appears 3 times in the output, file2.csv appears 2 times, and file3.csv appears just once.
The following code fragment is from CloseArchive, where the output stream is being generated:
if self.archiveType == 'zip':
if os.access(self.archiveFile, os.F_OK) and zipfile.is_zipfile(self.archiveFile):
self.archive = zipfile.ZipFile(self.archiveFile, "r")
outRec = self.output.newRecord()
# Archive file info
for info in self.archive.infolist():
outRec["FileName"] = info.filename
outRec["ArchiveName"] = self.archiveFile
outRec["DateTime"] = info.date_time
outRec["FileSize"] = info.file_size
self.output.write(outRec)
# Check the Archive File for bad files
badFile = self.archive.testzip()
# Close the Archive File again
self.archive.close()
if badFile == None:
pass
else:
raise braininfo.BrainNodeException, 'Archive contains bad file: "' + str(badFile) + '"'