Luke,
You need to use two modules (coming with standard Perl installation) to do this.
use File::Copy;
use File::Basename;
my $d1 = 'c:\infilesA';
my $d2 = 'c:\bkup_dir';
opendir DIR "$d1" or die "Could not open dir: $!\n";
my @fn = grep /\.dat/, readdir DIR;
closedir DIR;
for my $i (0..$#fn) {
copy "$d1/$fn[$i]", "$d2/$fn[$i].bkp";
}
my $d3 = 'c:\infilesB";
opendir DIR, "$d3" or die "Could not open dir - $d3: $!\n";
@fn = grep /\.dat/, readdir DIR;
closedir DIR;
my ($sec,$min,$hour,$mday,$mo
localtime(time);
my $yr = 1999+$year;
my $mm = $mon + 1;
my $ct = "$yr$mm$mday.$hour$min";
for my $i (0..$#fn) {
my ($name,$path,$suffix) = fileparse("$fn[$i]","\.dat
copy ("$d3/$fn[$i]", "$d2/$name$ct.dat");
}
Hope it works for you.
GT
Main Topics
Browse All Topics





by: snifferproPosted on 2003-12-23 at 10:33:09ID: 9992708
Hey luke_airig
dat" => "c:\\bkup_dir\\b20031223.d at.bck");
n,$year,$w day,$yday, $isdst) = localtime(time);
dat" => "c:\\bkup_dir\\$filename") ;
The module to use is "Win32::FileOp", for example to move one file try this ....
use Win32::FileOp qw(Move);
Move ("c:\\infilesA\\b20031223.
To add a date to the filename try this ...
use Win32::FileOp qw(Move);
my ($sec,$min,$hour,$mday,$mo
$year += 1900;
$mon += 1;
$date = "$day$mon$year";
$filename = join("b20031223.dat", $date, "");
Move ("c:\\infilesA\\b20031223.
hope this helps.