Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: I cannot create backup copy during file name change

by Marshall (Canon)
on Jul 25, 2012 at 04:50 UTC ( [id://983548]=note: print w/replies, xml ) Need Help??


in reply to I cannot create backup copy during file name change

A "rename" or "move to another directory" is normally a very efficient file system operation. It will not normally "destroy" the source until the "destination' has been created - this is basically a modification of a directory entry - no actual file bits on the disk get changed, just "pointers" to those bits.
#!/usr/bin/perl -w use strict; my $newdir ="something"; foreach my $file (glob "*.txt") { rename $file, "$newdir/$file" or warn "rename $file to $newfile failed: $!\n"; } # $file will still exist if rename fails
There is no need to make a back-up of a file before you rename it ("move" it to another directory). There are differences between copy and mv but basically it will work or it will not. If not, the original file is left intact.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-04-20 04:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found