473,287 Members | 3,295 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

Need Help with Zip File.

What I want to do is zip up my drive and not include the Windows folder or program files folder.

This is what I have and I can't get it to work.
Someone please help.




import os, zipfile
from os.path import join

user = os.getenv("username")
computername = os.getenv("computername")
docs = ("c:\\Documents and settings\\" + user + "\\My Documents\\")
block = ("Windows")

zip = zipfile.ZipFile("backup.zip", 'w')
for root, dirs, files in os.walk("c:\\dell\\"):
for fileName in files:
if block in files:
print FileName
else:
zip.write(join(root,fileName))
zip.close()
Oct 16 '07 #1
1 1592
What I want to do is zip up my drive and not include the Windows folder or program files folder.

This is what I have and I can't get it to work.
Someone please help.




Expand|Select|Wrap|Line Numbers
  1. import os, zipfile
  2. from os.path import join
  3.  
  4. user = os.getenv("username")
  5. computername = os.getenv("computername")
  6. docs = ("c:\\Documents and settings\\" + user + "\\My Documents\\")
  7. block = ("Windows")
  8.  
  9. zip = zipfile.ZipFile("backup.zip", 'w')
  10. for root, dirs, files in os.walk("c:\\dell\\"):
  11.     for fileName in files:
  12.         if block in files:
  13.             print FileName
  14.         else:
  15.             zip.write(join(root,fileName))
  16. zip.close()
What about your script isn't working? It doesn't look like it's blocking Windows, but is it causing any errors when you run it?
I modified your code so it worked on my computer, so hopefully that will help you.

Expand|Select|Wrap|Line Numbers
  1. import os, zipfile
  2. from os.path import join
  3.  
  4. block = ("c:\\WINDOWS", "c:\\Program Files")
  5. #use full pathnames so other directories with the same name arn't ignored
  6. #remember that the pathnames are case sensitive
  7.  
  8. zip = zipfile.ZipFile("backup.zip", 'w')
  9. for root, dirs, files in os.walk("c:\\"):
  10.     for fileName in files:
  11.         for path in block:
  12.             if path in root:#check the root, not the files
  13.                 break
  14.         else:
  15.             try:
  16.                 zip.write(join(root,fileName))
  17.             except:
  18.                 print root + fileName, "not zipped"
  19.  
  20. zip.close()
Oct 17 '07 #2

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

Similar topics

1
by: ADE | last post by:
Hi everyone well from my last post I found what I am looking for I have some code now that transfers files I have added a GUI to it and need some help with two things one my loadtemplate()...
5
by: Mariusz Sakowski | last post by:
Can someone translate this code to a C++? repeat file.Read(bufor, 1); for p := 1 to KeyCount do begin buf := buf xor Keys; end; targetFile.Write(bufor, 1); until file.Size = file.Position;
2
by: Keith Kowalski | last post by:
I anm opening up a text file reading the lines of the file that refer to a tif image in that file, If the tif image does not exist I need it to send an email stating that the file doesn't exist...
66
by: genestarwing | last post by:
QUESTION: Write a program that opens and read a text file and records how many times each word occurs in the file. Use a binary search tree modified to store both a word and the number of times it...
8
by: skumar434 | last post by:
i need to store the data from a data base in to structure .............the problem is like this ....suppose there is a data base which stores the sequence no and item type etc ...but i need only...
46
by: Bruce W. Darby | last post by:
This will be my very first VB.Net application and it's pretty simple. But I've got a snag in my syntax somewhere. Was hoping that someone could point me in the right direction. The history: My...
20
by: mike | last post by:
I help manage a large web site, one that has over 600 html pages... It's a reference site for ham radio folks and as an example, one page indexes over 1.8 gb of on-line PDF documents. The site...
2
by: Anders B | last post by:
I want to make a program that reads the content of a LUA array save file.. More precicely a save file from a World of Warcraft plugin called CharacterProfiler, which dumps alot of information about...
25
by: Jon Slaughter | last post by:
I have some code that loads up some php/html files and does a few things to them and ultimately returns an html file with some php code in it. I then pass that file onto the user by using echo. Of...
3
by: Eric_Dexter | last post by:
I am trying to take some data in file that looks like this command colnum_1 columnum_2 and look for the command and then cange the value in the collum(word) number indicated. I am under...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.