Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks!
I am using this module Archive-Zip and it is working fine, but when a file gets zipped it is also making a duplication of it. I found some help on their website, but I can't understand what they mean here:
From the help page:
"Duplicate files in Zip? ^ Q: Archive::Zip let me put the same file in my Zip twice! Why don't you prevent this? A: As far as I can tell, this is not disallowed by the Zip spec. If you think it's a bad idea, check for it yourself:"
$zip->addFile($someFile, $someName) unless $zip->memberNamed($someName +);

"I can even imagine cases where this might be useful (for instance, multiple versions of files)."

Whatever they are asking to be done to correct the issue doesn't work. I wonder if anyone here had the some problem with that.
Here is some of my code:
$zfile = $pathtofile; $zip = Archive::Zip->new(); my $zipped; #Chopped log files and Zipped files will be created in the directories + below: my $zip_file = $path_only."/".$file_name.".zip"; $zipped = $zip->addFile($zfile); $zipped->desiredCompressionMethod( COMPRESSION_DEFLATED ); find(\&zip_file, $dir); die 'write error' unless $zip->writeToFileNamed( $zip_file ) == AZ_OK; sub zip_file { my $zipped = $zip->addFile( $File::Find::name ); if ($File::Find::name =~ m/\.txt$/i){ my $zipped = $zip->addFile( $File::Find::name ); }

Thanks for the Help!

Replies are listed 'Best First'.
Re: Duplicated Zip files
by ahmad (Hermit) on May 11, 2006 at 16:27 UTC

    Hello ,

    actually , as i can see you posted the answer yourself

    you have to check it yourself

    # Add a file if it's not exsits in the zip Archive $zip->addFile($someFile, $someName) unless $zip->memberNamed($someName +);

    and i think this is wrong in your code

    if ($File::Find::name =~ m/\.txt$/i){ my $zipped = $zip->addFile( $File::Find::name ); }

    you are declaring "$zipped" inside your (if statment) so it will not be used outside it , if you do not really require it ... just change it as stated above ... addFile unless it's exsits in the Archive

    HTH

Re: Duplicated Zip files
by sgifford (Prior) on May 11, 2006 at 16:21 UTC
    Do you mean the file shows up in the Zip archive multiple times? Are you putting it there multiple times? For example, if in zip_file you just print the filename, does it print multiple times?