in reply to Moving log files, create folder based on local time/date & zip them up based on local time & date.

First suggestion -- use code tags.

Instead of shelling to winzip, have you considered using Archive::Zip?
my $zip = Archive::Zip->new(); my $member = $zip->addFile( 'logfile.log' ); my $status = $zip->writeToFileNamed( 'dated_filename.zip' ); die "error somewhere" if $status != AZ_OK;
As for naming the file, here is what I use:

my $tempDate = getDate(); my $outfile = $tempDate . ".zip"; sub getDate { my $date; my($day, $mon, $year) = (localtime)[(3,4,5)]; $date = $mon . $day . $year; return $date; }
The fact that the files are located on another server shouldn't make much difference. Make sure you properly escape the backslashes...this should be enough to get you started.

mike
  • Comment on Re: Moving log files, create folder based on local time/date & zip them up based on local time & date.
  • Select or Download Code

Replies are listed 'Best First'.
Re: Re: Moving log files, create folder based on local time/date & zip them up based on local time & date.
by Anonymous Monk on Sep 09, 2002 at 19:13 UTC
    Hi Mike, No I haven't tried the Archive::Zip module. Can I take all the logs in that directory, zip it up and name it based on local time and date with this module? Is so can you give me some example... thanks, anthony
      opendir FILES, $dir_name; my @files = readdir FILES; closedir FILES; my $zip = Archive::Zip->new(); $zip->addFile($_) for @files; my $date = join "_", ((localtime)[3,4,5]); my $status = $zip->writeToFileNamed( "$date.zip" );
      Well, you could either loop through the contents of the directory and use the addFiles method or you could use Archive::Tree. The docs for this module are pretty good and have good examples throughout.

      As long as you're just talking about naming the zip file based on the date and time, the code from my earlier node should cover that.

      mike