note 36068 deleted from function.rename by didou
| From: | didou@php.net | Date: | Wed, 24 Sep 2003 17:38:44 +0000 |
| Subject: | note 36068 deleted from function.rename by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-57066@lists.php.net to get a copy of this message | ||
Note Submitter: aly@nepadsn.org
----
I have a strange behavior appearing while renaming a big set of files (seems to appear when there
are more than 300 files in the directory, i am using a redhat 9.0 newly installed, php 4.2.2 with
apache 2) :
my feeling is that the handler $handler=$thisdir->read()
with $thisdir=dir($path)
is getting modified all along the process and the while($handler=$thisdir->read() {
... renaming
}
is somehow restarting from the begining at some point so that if i have 500 files in the directory
it will loop 570 times for instance, so that 70 files will have been renamed twice...
This happens only when the name itself changes (adding or removing some characters), it won't
happen if i just do a lowercase or uppercase in the rename function.
Note that i do this outside of the publishing directory (i took care of applying the proper rights
to the directories, recursively)
Here is the code (i am adding '_1' before the file extension) :
$dir="/backup/photos/photos_catalog/test";
$type="psd";
$x = 0;
//echo is_dir($dir);
if(is_dir($dir)) {
$thisdir = dir($dir);
while($entry=$thisdir->read()) {
if(($entry!='.')&&($entry!='..')) {
$isFile = is_file($dir . '/' . $entry);
$temp = explode(".", $entry);
$x++;
if (($isFile) && (strtolower($type) == strtolower($temp[count($temp) - 1])))
{
$old = $entry;
$new = $temp[0].'_1.'.$type;
echo $x . ' = ' . $old . ' -> '. $new . '<br>';
rename($dir.'/'.$old,$dir.'/'.$new);
}
}
}
}