title: Weird behaviour of rename() in PHP
body: <p>I am having a weird problem with my php. Whenever I try to move a file with rename(), not only the file is not moved, but also the directory to which it should be copied is deleted, together with all files within it. The original code is:</p>
  
  <pre><code>rename('temp.odt', 'tmp/report.odt');
  </code></pre>
  
  <p>but I have already tried other path delimiters like</p>
  
  <pre><code>rename('temp.odt', 'tmp\report.odt');
  
  rename('temp.odt', 'tmp\\report.odt');
  
  rename('temp.odt', 'tmp' . DIRECTORY_SEPARATOR . 'report.odt');
  
  rename('C:\wamp\www\zaiko\temp.odt', 'C:\wamp\www\zaiko\tmp\report.odt');
  </code></pre>
  
  <p>all to no avail. The code comes from a 3rd-party module which is used in the system I am working on.</p>
  
  <p>Points  well checked:</p>
  
  <ol>
  <li>The file 'temp.odt' does exist in the current directory;</li>
  <li>The directory 'tmp' does exist and there are several files in it. Also it is not read only.</li>
  <li>The target file does not already exist (the actual file name has a timestamp, I reduced it here for simplicity)</li>
  </ol>
  
  <p>After running rename(), the 'temp.odt' file is intact in its original location, while the folder 'tmp' is <strong>vanished</strong> as well as everything inside it. The following warning is issued:</p>
  
  <p>( ! ) Warning: rename(temp.odt,tmp\report.odt) [function.rename]: The system couldn't find the specified path*. (code: 3) in C:\wamp\www\zaiko\modules\mod_deliver.php on line 192</p>
  
  <p>*translated from Portuguese</p>
  
  <p>Running: Apache 2.2.17 with PHP 5.3.5 on Windows XP with NTFS</p>
  
  <hr>
  
  <p><em><strong>Editing:</em></strong></p>
  
  <p>Just found the cause of the problem. It turns out that the module used by the application uses, in turn, a compression library; this library uses a temporary folder with exactly the same name as the one used by the application.</p>
  
  <p>It must use some sort of cache, which would explain why the error didn't appear 100% times. </p>
  
  <p>Problem solved by changing the name of the 'tmp' folder to anything else.</p>
  
  <p>Thank you all for your time, and sorry for bothering you with such a stupid thing that, as it turns out, had absolutely nothing to do with my initial guess and, consequently, with the question formulated.</p>