in reply to Re^6: Creating a .zip file using perl
in thread Creating a .zip file using perl

Thanks monks.zip file is getting created but with no data all..i dont see any .lib files in there,there still seems to be a bug.can someone run the below code on a sample directory with libs and see if the zip contains .libs.Please help

use Archive::Zip qw( :ERROR_CODES :CONSTANTS ); use File::Spec; use strict; use warnings; my $zipfile = shift or die "What's the zipfile?"; my $dir = shift or die "Where's the dir?"; my $zip = Archive::Zip->new(); opendir my $dh, $dir or die $!; print "\nDIR:$dir"; while ($_ = readdir( $dh)) { next if !/\.lib$/; $zip->addFile(File::Spec->catfile($dir, $_), $_); } closedir $dh; # Save the Zip file unless ( $zip->writeToFileNamed($zipfile) == AZ_OK ) { die 'write error'; }

Replies are listed 'Best First'.
Re^8: Creating a .zip file using perl
by Utilitarian (Vicar) on May 05, 2011 at 08:56 UTC
    Eh, I tested that and it works correctly, are there any files ending in .lib in the directory you are interested in (are you looking to check subdirectories or something else that you haven't mentioned?)

    print "Good ",qw(night morning afternoon evening)[(localtime)[2]/6]," fellow monks."

      I need to search recursively through subdirectories and then zip,not just in the current directory.Please help

        Beginners guide to File::Find provides examples of how to use File::Find to traverse a directory tree, simply put you need to add files to the zip if they match your criteria in the "wanted" function.

        You can use this rather than a direct directory read to provide you with your list of filenames to check. You'll have to work through spurperl's tutorial, but that way you'll have learned something from this exercise ;)

        print "Good ",qw(night morning afternoon evening)[(localtime)[2]/6]," fellow monks."