Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Add timestamp to file being copied.

by markkawika (Monk)
on Jun 08, 2009 at 23:30 UTC ( [id://769719]=note: print w/replies, xml ) Need Help??


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?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://769719]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-09-10 01:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.