Solved

Add to a already existing Zip file

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

705 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

19 Experts available now in Live!

Get 1:1 Help Now