Python: How to create zip of files?

Download Code From Here

import zipfile
import time
import os

def create_zip(zip_filenames):
  zipped_name='ZipFile'+str(time.strftime("%m%d%Y_%H%M%S"))+'.zip'
  print "Creating ", zipped_name
  zf = zipfile.ZipFile(zipped_name, mode='w')

for filename in zip_filenames:
  try:
    print "Adding",filename,"in",zipped_name
    zf.write(filename)
  except:
    ":::ERROR::: Unable to add file to zipped file"
     print "Created Zipped File",zipped_name 
     zf.close()

def remove_files(remove_filesnames):
  for filename in remove_filesnames:
    print "Removing", filename
    os.remove(filename)


if __name__=="__main__":

  filenames= ['syspreset001','syspreset0161.prst','zip']
  create_zip(filenames)
  remove_files(filenames)

Leave a Reply

Your email address will not be published. Required fields are marked *