删除365天前指定目录下指定类型文件 perl

Perl :



sub process {

  
 chomp($LogFileDir);
 if( $LogFileDir ne "" )
 {
  
  print "obtain log folder $LogFileDir\n";
  
  my @array;
  my @erroay;
  # get *.log files
  @array = glob "$LogFileDir/*.log";
  
   #print "  files is @array\n";
   # get *.err files
  @erroay = glob "$LogFileDir/*.err"; 
  # print "  files is @erroay\n";
  
  my $datstamp = Time::Piece->new->strftime('%m%d%Y');
  
  print "  start clean up *.log files\n";
  foreach my $logfile (@array) {
        
    if ( (stat "$logfile")[9] lt (time() - 365 * 86400)) {
      print "Deleting the input file '$logfile' as its 365 days old\n";
     unlink("$logfile") or die "No input file '$logfile' exists in the location - $LogFileDir\n";
     
    }
    
   }
   
   print "  start clean up *.err files\n";
  foreach my $logfile (@erroay) {
       
    if ( (stat "$logfile")[9] lt (time() - 365 * 86400)) {
      print "Deleting the input file '$logfile' as its 365 days old\n";
     unlink("$logfile") or die "No input file '$logfile' exists in the location - $LogFileDir\n";
     
    }
    
   }
   print " it finished to clean up files ";
   
 } else {

print " log folder $LogFileDir is null ";

}
 
}



你可能感兴趣的:(删除365天前指定目录下指定类型文件 perl)