keep the timestamp of files

M

mike

hi
I want to move some files to another directory. The problem is the
timestamp will change when i use File::Copy followed by an unlink of
the file.
How can i keep the timestamp of the file, much like using the shell
command mv ? any function in perl to do that?
thanks
 
S

Sam Holden

hi
I want to move some files to another directory. The problem is the
timestamp will change when i use File::Copy followed by an unlink of
the file.
How can i keep the timestamp of the file, much like using the shell
command mv ? any function in perl to do that?

Did you bother reading the documentation for File::Copy?

Obviously not since you named the function it provides to the
job in your post...
 
H

Herr Hardy

hi
I want to move some files to another directory. The problem is the
timestamp will change when i use File::Copy followed by an unlink of
the file.
How can i keep the timestamp of the file, much like using the shell
command mv ? any function in perl to do that?
thanks

Try

my @timestamp = ( stat($old_file)) [8,9];
utime @timestamp, $new_file;

before unlink;-)

Hardy
 
J

John W. Krahn

mike said:
I want to move some files to another directory. The problem is the
timestamp will change when i use File::Copy followed by an unlink of
the file.
How can i keep the timestamp of the file, much like using the shell
command mv ? any function in perl to do that?

If you just want to move the file then try Perl's built-in rename()
function.

perldoc -f rename


John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top