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

Hi Monks!
I am using this code to zip any file with extension .log. This program reads many lines entered with directories path to all the location where .log files are been generated.
The problem I am having is that, if one of these locations are, as an example:
c:/program/ and c:/program/other/more/ and c:/program/docs/, the program when it finds a path like this: c:/program it is going through all the directories found in it self as well. What I would like is, to the program to run specifically into "c:/program" and not to be scanning through all directories from there because that has already been specified in the path(s) entered before.
Is there a way to make sure that the directory path given only search at file level and ignore looking inside other directories inside itself?
Here is the part of the code that is doing that.

#Here I am zipping all the files in a specific directory $dir = $main_path_only; # This variable will have all the path to dire +ctories that has *.log file(s). $zip = Archive::Zip->new(); $zipped; #Chopped log files and Zipped files will be created in the directories + below: my $zip_file = $arch_path."/".$dir_archive."/"."$month$date-$year"."-n +ewlog.zip"; $zipped = $zip->addDirectory( $dir); $zipped->desiredCompressionMethod( COMPRESSION_DEFLATED ); find(\&zip_file, $dir); die 'write error' unless $zip->writeToFileNamed( $zip_file ) == AZ_OK; #End archiving ######ZIP SUB################################ sub zip_file { #$zipped = $zip->addFile( $File::Find::name ); if ($File::Find::name =~ m/\.log$/i){ $zipped = $zip->addFile( $File::Find::name ); } } #####END ZIP SUB###########################

Thanks for the Help!

Replies are listed 'Best First'.
Re: Reading at File Level in Directories
by Joost (Canon) on Jun 07, 2006 at 15:16 UTC
      It was a very good idea, it worked! Thanks!!!
      It was a very good idea, it worked!
      Thanks!!!
      #find(\&zip_file, $dir); foreach my $file (glob("$dir/*.log")) { $zipped = $zip->addFile( $file ); } die 'write error' unless $zip->writeToFileNamed( $zip_file ) == AZ_OK; #End archiving
Re: Reading at File Level in Directories
by sgifford (Prior) on Jun 07, 2006 at 15:46 UTC
    You can either keep track of the directories you have already archived, and before you start archiving each directory make sure you haven't already done it; or else pre-process your list of directories and remove any that are included in earlier directories.