Fri, 17 May 2024


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?

By: Peter, NetArt Media
Wed, 10 November 2021

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: Web Development
Share this post:



See All Scripts






Subscribe for our newsletter

Receive the latest blog posts direct in your mailbox