I wrote this script...
the script is in a file called backup_zip.py, and when I run the script its purpose is to zip up files in the directory that the script is in. However, currently it also zips up backup_zip.py (the script I wrote) and I don't want that. I tried preventing that above with the if i == 'backup.. but it didnt' work. How would i do this?
Code:
#!/usr/bin/python # Filename: backup_zip.py import os, zipfile, time, datetime, glob from os.path import splitext, relpath, split r = 1 cwd = os.getcwd() today = datetime.date.today() def backup(): for dirpath,dirs,files in os.walk(cwd): for file in files: z_path = os.path.relpath(dirpath) filename = os.path.split(cwd)[1] arcfile_name = r"%s_%s.zip" % (filename,today) fileList = [z_path] output = zipfile.ZipFile(arcfile_name, 'w', zipfile.ZIP_DEFLATED) print "\n " for i in fileList: if i == 'backup_zip.py': print '- backup_zip.py' else: print "archiving file '%s'" % (i) output.write(i) output.close() print "\n " if __name__=='__main__': while r == 1: print "This script when run backs up files in a directory by comressing them to zips. " begin = raw_input("Do you wish to back up files in this directory [type: yes or no] ") if begin == "yes": r = 1 backup() time.sleep(8) r = 0 break elif begin == "no": r = 0 else: print "Enter yes or no"
Comment