file copier (Rated 5)Description:
I knocked this up for a newbie on DS, who needed to move files over from one dir to another, but only if they were under 5 mins old (i.e. last touch) Code starts here
#!/usr/bin/perl
use strict;
use File::Copy;
my $age;
my $destination="/home/chris/tmp/";
my $sourcedir="/home/chris/bin/";
my @files=`cd $sourcedir && ls`;
# iterate and copy each one
foreach (@files){
chomp;
# get the age in seconds
$age = (time() - (stat($sourcedir.$_))[9]);
print "\n$sourcedir.$_ is is $age seconds old\n";
if($age<300){
copy("$sourcedir$_","$destination$_");
}
}
Submitted by christo on 11-06-2003 15:23 |