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!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.