def processArchives(filename, file_filter):
# Process zip file if required and return a list of files to process
files_to_process = []
if filename.endswith('.zip'):
try:
zip_archive_filename = filename
# Open the zip archive:
zip_archive = zipfile.ZipFile(zip_archive_filename, "r")
zipFileList = zip_archive.namelist()
zip_archive.close()
countTotalFiles = len(zipFileList)
logger.info("Total files in %s: %d" % (zip_archive_filename, countTotalFiles))
logger.info("Hold on while we check the zipped files...")
for zipped_filename in zipFileList:
if re.match(file_filter, zipped_filename):
files_to_process.append(os.path.join(zip_archive_filename, zipped_filename))
if len(files_to_process) == 0:
logger.error("No valid files found!")
except (IOError, zipfile.BadZipfile, struct.error), err:
logger.error("Error reading zip archive: %s" % zip_archive_filename)
exit(-1)
else:
files_to_process.append(filename)
return files_to_process
评论列表
文章目录