in reply to Add timestamp to file being copied.

Your question doesn't make clear what timestamp you want to use.

It appears from your code that you want to use the time that the script was run as the timestamp on the file, as opposed to the timestamp of the original file you were copying.

If that's the case, may I suggest:

use File::Copy; my ($sec, $min, $hour) = localtime(); foreach my $upload (@uploads) { my $newName = $upload; $newName =~ s/\.zip$/${hour}:${min}:{sec}.zip/; copy ($logSite . ${upload}, $localCpPath . $newName) or die "Failed to copy "$upload"; print "File $upload has been copied over and renamed $newName\n"; }

Replies are listed 'Best First'.
Re^2: Add timestamp to file being copied.
by Karger78 (Beadle) on Jun 09, 2009 at 14:34 UTC
    Hello, It seems to work. I made one minor changes as the month day and year seem to be a better identifer.
    foreach my $upload (@uploads) { my $newName = $upload; $newName =~ s/\.zip$/-${mday}-${mon}-${year}.zip/; copy ($logSite . ${upload}, $localCpPath . $newName)or die "F +ailed to copy"; print "File $upload has been copied over and renamed $newName +\n"; }
    I had one further question. I forgot to mention the files can eitehr be .zip or .zip.meta Now I see that we are only zip files with the pattern matching. What would be the best way so it changes the meta file aswell. If statement perhaps in the middle of the for loop?