in reply to Re^3: copy isn't working
in thread copy isn't working

I tried both these options but didn't work.

my $toDate = localtime->strftime('%Y-%m-%d_%H%M%S');

my $toDate = localtime->strftime('%Y-%m-%d_%H_%M_%S');

Replies are listed 'Best First'.
Re^5: copy isn't working
by poj (Abbot) on Mar 08, 2019 at 16:37 UTC

    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

    poj
Re^5: copy isn't working
by BillKSmith (Monsignor) on Mar 08, 2019 at 16:06 UTC
    Space is a valid character in windows long filenames, but names containing spaces often require special quoting. I would at least consider using a regex to modify your time stamp to satisfy your requirements without violating window's constraints.
    Bill