×
Home About Us Products Services News Free Scripts Contact
news php scripts and software

Perl example - How to create a program whose input is a piped in directory command and whose output is stdout, and whose output represents a batch file which copies every file (not directory) older than specific date?


Perl - How to create a program whose input is a piped in directory command and whose output is stdout, and whose output represents a batch file which copies every file (not directory) older than specific date?

while(<STDIN>)
  {
  my($line) = $_;
  chomp($line);
  if($line !~ /<DIR>/)         #directories don't count
    {
    #** only lines with dates at position 28 and (long) filename at pos 44 **
    if ($line =~ /.{28}(\d\d)-(\d\d)-(\d\d).{8}(.+)$/)
      {
      my($filename) = $4;
      my($yymmdd) = "$3$1$2";
      if($yymmdd lt "971222")
        {
        print "copy $filename \\oldie\n"; 
        }
      }
    }
  }

Category: Perl

 
<< Go back