473,785 Members | 2,557 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Keep windows from zipping up a file.

30 New Member
I wrote this script...

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/python
  2. # Filename: backup_zip.py
  3.  
  4. import os, zipfile, time, datetime, glob
  5. from os.path import splitext, relpath, split
  6.  
  7. r = 1
  8. cwd = os.getcwd()
  9. today = datetime.date.today()
  10.  
  11. def backup():
  12.  
  13.    for dirpath,dirs,files in os.walk(cwd):
  14.  
  15.       for file in files:
  16.  
  17.          z_path = os.path.relpath(dirpath)
  18.          filename = os.path.split(cwd)[1]
  19.          arcfile_name = r"%s_%s.zip" % (filename,today)
  20.          fileList = [z_path] 
  21.  
  22.          output = zipfile.ZipFile(arcfile_name, 'w', zipfile.ZIP_DEFLATED)
  23.  
  24.          print "\n "
  25.          for i in fileList:
  26.             if i == 'backup_zip.py':
  27.                print '- backup_zip.py'
  28.             else:
  29.                print "archiving file '%s'" % (i)
  30.                output.write(i)
  31.          output.close()
  32.          print "\n "
  33.  
  34.  
  35. if __name__=='__main__':
  36.  
  37.    while r == 1:
  38.  
  39.       print "This script when run backs up files in a directory by comressing them to zips. "
  40.       begin = raw_input("Do you wish to back up files in this directory [type: yes or no] ")   
  41.  
  42.       if begin == "yes":
  43.          r = 1
  44.          backup()
  45.          time.sleep(8)
  46.          r = 0
  47.          break
  48.       elif begin == "no":
  49.          r = 0
  50.       else:
  51.          print "Enter yes or no"
  52.  
  53.  
  54.  
  55.  
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?
Oct 22 '08 #1
1 1325
bvdet
2,851 Recognized Expert Moderator Specialist
I took out some things that I thought unnecessary, and moved assignment of output out of the for loop. This will skip the script.
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/python
  2. # Filename: backup_zip.py
  3.  
  4. import os, zipfile, time, datetime, glob
  5. from os.path import splitext, split
  6.  
  7. cwd = os.getcwd()
  8. today = datetime.date.today()
  9.  
  10. def backup():
  11.     filename = os.path.split(cwd)[1]
  12.     arcfile_name = r"%s_%s.zip" % (filename,today)
  13.     output = zipfile.ZipFile(arcfile_name, 'w', zipfile.ZIP_DEFLATED)
  14.  
  15.     for dirpath,dirs,files in os.walk(cwd):
  16.         for f in files:
  17.             fn = os.path.join(dirpath, f)
  18.             if f == 'backup_zip.py':
  19.                 print '- backup_zip.py'
  20.             else:
  21.                 print "archiving file '%s'" % (fn)
  22.                 output.write(fn)
  23.     output.close()
  24.     print "\n "
  25.  
  26.  
  27. if __name__=='__main__':
  28.  
  29.     print "This script when run backs up files in a directory by comressing them to zips. "
  30.     begin = raw_input("Do you wish to back up files in this directory [type: yes or no] ")   
  31.  
  32.     if begin == "yes":
  33.         backup()
You should realize that this archives files in subdirectories under your current working directory.
Oct 23 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
2177
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 COMMAND BASED UPON STRING $zipName = ($album) ? "${section}s_$album" : "${section}s"; $zipName .= '.zip';
0
1247
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 yet) 2) in the Elapseed event the service will query a table in sql server and find the 1 oldest row in a table and set the status of that row to 'running' 3) the service will then run a report on the sql server database and save the results to a...
0
1171
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 for zipping our webservers logfiles. after zipping all files, i've tried to delete all files, but i couldnt. i got an error message that i cannot delete a file, because it is still in use. Here my two functions for that:
6
2404
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 send few jpg files at the same time. The problem that I am facing is that the client needs to print some files that are saved on the server. Usually before printing user needs to resize them. It would be the best if image opens right away in the...
9
5515
by: ReidarT | last post by:
How can I zip (compress) a file in vs2005 with windows own zip-program? reidarT
4
1733
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 alternatives. I found some modules in Perl which does zipping. I guess it goes by the name 'gzip'. I plan to write the zipping feature in Perl and import it into Python.
2
4117
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 ); File is being uploaded by the apache server, but it's not being zipped. My guess "\", escaping, is causing problem in windows path. Do I also have to escape the $movedFile content? Forexample $movedFile= "c:\web\upload\someFile".
1
1508
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 result. As I see, this module is "a command line tool" imported as extension. Now I search for something that can handle the characters good, or handle the unicode filenames.
5
2295
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 Application, does not work while I run it with Windows services. In my Windows application I am able to zip the whole 900Mb without any problems, but in my windows services I am not able to zip the whole 900Mb. In Windows Services it throws an...
0
9647
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10161
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10098
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8986
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7506
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5390
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3662
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2890
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.