Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Add to a already existing Zip file

Posted on 2004-09-07
4
Medium Priority
?
403 Views
Last Modified: 2006-11-17
The following code is fine for creating a new zip file and adding files to it, but how does one add files to an already existing Zip file?

$zip_dir='c:\temp\test';
$zip_file_name='file.zip';

use Archive::Zip qw( :ERROR_CODES :CONSTANTS );

##  Read names of all files in the directory
@files=<$zip_dir/*>;

my $zip = Archive::Zip->new();
my $member = $zip->addDirectory( $zip_dir);

foreach (@files){ ##  Add each file in that directory to the .zip archive.
 $member = $zip->addFile($_);
}

die 'Cannot create $zip_file_name: $!\n' if $zip->writeToFileNamed($zip_file_name) != AZ_OK;
0
Comment
Question by:dfr031260
4 Comments
 
LVL 3

Accepted Solution

by:
alskdj80 earned 500 total points
ID: 12000435
if you're using Archive::Zip before v1.02, you will not have overwrite() functions... you will have to write to a temp zip file and then replace the old one you have...

if you do have v1.02 or above, then you'll have overwrite()... so just use overwrite instead of writeToFileNamed...

ie:
$zip->overwrite($zip_file_name) instead of $zip->writeToFileNamed($zip_file_name)

i believe that should work
0
 

Author Comment

by:dfr031260
ID: 12000583
Thank you.

David
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question