I wrote this script... - #!/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"
-
-
-
-
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?
1 1295 bvdet 2,851
Expert Mod 2GB
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: comp.lang.php |
last post by:
Has anyone had any luck with file zipping utilities for PHP 4-5 and
Windows XP with Apache 2.0.53?
Following is my code snippet:
PHP Code:
if ($this->isSuccessful) { // RUN ZIP...
|
by: Antonio |
last post by:
Hi, I am building a windows service that does the following
1) a System.Timers.Timer elapseed event handler will run code at every
interval, maybe every 2 to 5 minutes or so (i have not decided...
|
by: Benjamin Bittner |
last post by:
hallo ng,
first of all, for the zipping progress i use the ziplib from
http://www.icsharpcode.net/OpenSource/SharpZipLib/Default.aspx
now to my problem.
im trying to build a little application...
|
by: Shimon Sim |
last post by:
Hi
1) Is it possible to force browser to open image in default windows
application? That is what specifies in Folder Options for jpg extension.
2) Also if the 1) is possible is it possible to...
|
by: ReidarT |
last post by:
How can I zip (compress) a file in vs2005 with windows own zip-program?
reidarT
|
by: sri2097 |
last post by:
Hi all,This is in reply to the 'Compressing folders in Windows using
Python' query I raised y'day.
I figured out that windows does not allow command line zipping so I
started looking for...
|
by: johnny |
last post by:
I have the following code. What I need is to zip the file
(c:\web\upload\someFile) to d:\web\someFile.zip.
$cmd = 'c:\zip\zip.exe '. $movedFile. ' '. $finalFile;
exec( $cmd, $cmd_output );
...
|
by: durumdara |
last post by:
Hi!
As I experienced in the year 2006, the Python's zip module is not
unicode-safe.
With the hungarian filenames I got wrong result.
I need to convert iso-8859-2 to cp852 chset to get good...
|
by: =?Utf-8?B?dmlzaHJ1dGg=?= |
last post by:
This code works fine in Windows Application.
In Windows Application, I am able to zip the image files properly and it
totally contains 900MB
My problem is the same code which I used in my Windows...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: tracyyun |
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
|
by: NeoPa |
last post by:
Hello everyone.
I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report).
I know it can be done by selecting :...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM)
Please note that the UK and Europe revert to winter time on...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
|
by: GKJR |
last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
| |