php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39379 something worong with function rename()
Submitted: 2006-11-04 16:20 UTC Modified: 2006-11-08 13:52 UTC
From: roast@php.net Assigned:
Status: Not a bug Package: *Directory/Filesystem functions
PHP Version: 5.2.0 OS: windows xp sp2
Private report: No CVE-ID: None
 [2006-11-04 16:20 UTC] roast@php.net
Description:
------------
When I use function rename() to rename a folder by recursion.
But it doesn't work as usual.It renamed the file twice.

Reproduce code:
---------------
function addDomain($directory)
{
	if (is_dir($directory))
	{
		$dirHandle = opendir($directory);	
		
		while ($file = readdir($dirHandle))
		{
			if ($file != '.' && $file != '..')
			{
				if (is_dir($file))
				{	
					//do nothing;
				}
				else 
				{
					rename($directory.$file,$directory.$file.'r');
					echo $directory.$file.'<br>';
				}
			}
		}
		
		closedir($dirHandle);
	}
}

addDomain("test/");

Expected result:
----------------
test/Q4.php<br>test/Q5.php<br>

Actual result:
--------------
test/Q4.php<br>test/Q5.php<br>test/Q4.phpr<br>test/Q5.phpr<br>

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-11-08 13:52 UTC] tony2001@php.net
Your function reads the directory and creates files in it in the same time.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 30 14:01:28 2024 UTC