User Contributed Notes: rename
baghera@mindspring.com
11-Oct-1999 04:42
This function apparently works relative to the directory your *script* is in, not the directory the file you are moving is in. Therefore your destination directory must reflect the location of your script.
baghera@mindspring.com
13-Oct-1999 11:52
That is, if you are using this function to move a file instead of simply renaming it.
michael-nospam@sal.mik.hyperlink.net.au
24-Nov-1999 11:43
Note, that on Unix, a rename is a beautiful way of getting atomic updates to files.
Just copy the old contents (if necessary), and write the new contents into a new file, then rename over the original file.
Any processes reading from the file will continue to do so, any processes trying to open the file while you're writing to it will get the old file (because you'll be writing to a temp file), and there is no "intermediate" time between there being a file, and there not being a file (or there being half a file).
Oh, and this only works if you have the temp file and the destination file on the same filesystem (eg. partition/hard-disk).
darin@flashcom.net
28-Feb-2000 02:58
on Win98 specify the whole path but with forward slashes:
rename("C:/usr/" . $filename, "C:/usr/temp/" .$newfile);
wren@i.am
02-Mar-2000 06:25
When renaming files, be careful if you already have a file with the destination file name, as rename will overwrite it. As far as I'm concerned, this is a bug, seeing as this is _not_ a move function; rename should instead throw an error.
musicmaker@newfutureweb.com
12-Mar-2000 09:51
Note however, that <b>rename will not move a file to a different file system</b> on Linux. I beleive that as a previous comments suggests, there should be a 'move' command that parallels UNIX's mv command, and a 'rename' command that is a pure rename function, and would throw errors overwriting and crossing file systems.
cleong@organic.com
29-Mar-2000 04:36
rename() doesn't seem to overwrite files on NT. The behavior is an OS-dependent side-effect I guess.
cleong@organic.com
29-Mar-2000 04:41
Note that it *IS* possible to rename across drives on NT. So rename("c:\\a.doc", "a:\\b.doc") would succeed.
max@tocrawl.com
02-Jul-2000 05:45
Is that possibly to change a filename into something like this:
from /old/mydir/myfile.html
to /new/nydir/myfile.html
?
sapperlot@gmx.net
11-Jul-2000 04:44
If I try to use rename($userfile, $targetpath . "/" . $targetfile) on a WinNT machine, I get the errormsg "Warning! No such process"...
What is wrong?
ar.montgomery@metallo.com
28-Jul-2000 08:48
Personally, I am not sure if this is a bug, but it is bothering the heck out of me! I keep getting a warning error when ever I try to rename a file on my Win2000 box. The file I am trying to rename does exist and is found by the file_exists method provided by PHP. Here is a excerpt of what I was doing...
<pre><? $old="test.phtml"; $new="test2.phtml"; if(file_exists($old)) print("well, we did find the old file!"); rename($old, $new); print("Done!"); ?><pre>
Any assistance would be great!