PDA

Click to See Complete Forum and Search --> : [Resolved] Move File


toto
Sep 8th, 2003, 04:51 PM
Hello,

This is probably a stupid question, but does anyone know how to move a file on the same system as the php script is running?

The problem I run into is I have only found a way to do this by using the copy command and then deleting the old file (unlink) this however resets all the attributes on the file..creation time..modification time..accessed time.. Which I happen to need to keep!

Thanks guys,
Mitchel

kows
Sep 8th, 2003, 06:22 PM
I think you're looking to rename() the file.

Something like this:

<?
rename(
"c:/web/file.txt", //old file
"c:/web/dir/dir/file.txt" //new file
);
?>


I can't say I know if it keeps the file attributes or not, but I'm sure you could try it out and find that out for yourself. Here's the PHP.net full coverage:

http://ca.php.net/manual/en/function.rename.php

toto
Sep 8th, 2003, 07:24 PM
Cool, Thanks, I'm going to try that as soon as I have a minute, I'll get back and let you all know if it works.

Mitchel

toto
Sep 8th, 2003, 08:25 PM
Thanks kows, that works perfectly.

Mitchel