Solved

Add to a already existing Zip file

Posted on 2004-09-07
4
383 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 125 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
binary to char / hexadecimal 5 104
Using Perl to parse rows 7 93
Regular Expression for URL 10 91
Call Shell Script from Perl Script 6 77
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

895 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now