ZIP files

Oriana oriana.falco at thalesesec.com
Wed Nov 10 11:05:28 EST 2004


Hi!


I'm beginning to use the zipfile module in Python and I'm confused
about something. I am trying to extract certain files from one zip and
copy them into another one. This is the code I‘ve got so far:

 
import string 
import os, re
from zipfile import *

 
path= raw_input("\n Please enter the zipfile to be copied: ")

new_zip= ZipFile('something.zip', 'w')


orig_zip=ZipFile(path, 'r')
zip_files= orig_zip.namelist()
 

for file in zip_files:
    if  file[-2:] == '.c' or file[-2:] == '.h' or file[-4:] == '.exe':
        tempfile = open(file,'w')
        x = orig_zip.read(file)
        tempfile.write(x)
        tempfile.close()
        new_zip.write(file)

 

So far, this code does the work, but I think it's to much work for
just copying entire files
Is there any other way to do this????
Basically, what I want to do is create a copy of the zip but with a
different name
thanks in advance, Oriana



More information about the Python-list mailing list