I took out some things that I thought unnecessary, and moved assignment of
output out of the for loop. This will skip the script.
- #!/usr/bin/python
-
# Filename: backup_zip.py
-
-
import os, zipfile, time, datetime, glob
-
from os.path import splitext, split
-
-
cwd = os.getcwd()
-
today = datetime.date.today()
-
-
def backup():
-
filename = os.path.split(cwd)[1]
-
arcfile_name = r"%s_%s.zip" % (filename,today)
-
output = zipfile.ZipFile(arcfile_name, 'w', zipfile.ZIP_DEFLATED)
-
-
for dirpath,dirs,files in os.walk(cwd):
-
for f in files:
-
fn = os.path.join(dirpath, f)
-
if f == 'backup_zip.py':
-
print '- backup_zip.py'
-
else:
-
print "archiving file '%s'" % (fn)
-
output.write(fn)
-
output.close()
-
print "\n "
-
-
-
if __name__=='__main__':
-
-
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":
-
backup()
You should realize that this archives files in subdirectories under your current working directory.