glob returns full path so $archiveFileName will include the directory.
my $archiveFileName = $file."_".$toDate.".txt";and in the copy here you are adding the archive directory on to it
print "copy $file, $archiveFileName\n"; copy ($file, "C:\\data\\app\\AppSpecific1\\Archive\\".$archiveFileName +) or die "Copy failed: $!";
It might be easier to use readdir. For example
#!perl use strict; use warnings; use Time::Piece; use File::Copy; my $toDate = localtime->strftime('%Y-%m-%d_%H%M%S'); my $dir = 'C:/data/app/AppSpecific1/In'; my $archiveDir = 'C:/data/app/AppSpecific1/archive'; opendir (my $dh, $dir) or die "Can't opendir $dir: $!"; while (my $file = readdir $dh) { next unless $file =~ /^test/; # filter as reqd my $srcFile = "$dir/$file"; next unless -f $srcFile; my $destFile = $archiveDir.'/'.$toDate.'_'.$file; print "copy $srcFile, $destFile\n"; copy ( $srcFile, $destFile) or die "Copy failed '$srcFile' to '$destFile' : $!"; } closedir $dh;
Using the same variable in the print and the copy wil help debugging
pojIn reply to Re^5: copy isn't working
by poj
in thread copy isn't working
by YellowJackets
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |