New to Python, but old to programming. I have come here because no matter when I search for a Python reference, my best answers have been here. And when it comes to the current question, believe me I have looked here, extensively, and while I get the answers I want, they do not always work.
So Here's my question. Very simple, I just want to use Python to zip files up, and verify said zip file.
Here is the relevant code :
import zipfile
archive_file_list = ['archive1','archive2']
LogIt(log_file,"checking for existance of archive directory")
if os.path.isdir(archive_path) == True:
LogIt(log_file,'archive directory found')
LogIt(log_file,'looking for files to archive')
for a in archive_file_list:
target_file = archive_path + a + '.txt'
LogIt(log_file,'looking for file : ' + target_file)
if os.path.isfile(target_file) == True:
LogIt(log_file,'file found')
zip_file = archive_path + a + '.zip'
LogIt(log_file,'creating zip file : ' + zip_file)
zf = zipfile.ZipFile(zip_file,'w')
zf.write(target_file,zip_file,compress_type=zipfile.ZIP_DEFLATED)
zf.close
LogIt(log_file,'Zip file created')
LogIt(log_file,'verifying')
if os.path.isfile(zip_file) == True:
LogIt(log_file,'zip file exists')
LogIt(log_file,'verifying zip file')
if zipfile.is_zipfile(zip_file) == True:
LogIt(log_file,'file ' + zip_file + ' verified')
else:
LogIt(log_file,'file ' + zip_file + ' not verified')
# print_info(zip_file)
else:
LogIt(log_file,'unable to verify zip file')
else:
LogIt(log_file,'file not found')
else:
LogIt(log_file,'archive path not found, no files to zip')
For the most part it works fine, the designated file is zipped. I can read it via pkzip or Rar on any of the machines I move it to. But when I actually check to see if this is a valid zip file, I get shut down, looking at the file with a decent editor shows that it does begin with "PK", or "Pk", I forget, but it certainly appears to be valid.
if zipfile.is_zipfile(zip_file) == True:
this always returns False, I just don't get it.
Thanks in advance for your assistance. jim