Solved

Add to a already existing Zip file

Posted on 2004-09-07
4
395 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

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…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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

729 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