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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
4 + 36 = ?
Subscribe to this entry?

 
 [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

Add a Patch

Pull Requests

Add a Pull Request

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: Fri Apr 19 14:01:30 2024 UTC