550 Can't remove directory: Directory not empty

Status
Not open for further replies.

9svn6

New Member
Messages
77
Reaction score
0
Points
0
Hi I have been having a lot of problems lately when deleting files and folders for some reason I always end up with a few files or folders that wont delete and I get this error:

Code:
550 Can't remove directory: Directory not empty

even tho the directory is either empty or I'm trying to delete the files inside. I have noticed if I chmod each file / folder to 755 then they will delete but it is annoying when you have to chmod each file and folder one at a time since the batch would give me the error that i wasn't permitted.
 
Last edited:

DefecTalisman

Community Advocate
Community Support
Messages
4,148
Reaction score
5
Points
38
You could try this little php script to remove everything in a directory and the directory itself.

PHP:
<?php

$dir_stack = array('test/'); // put the directory to delete here **NOTE** everything in this will be deleted.
$i = 0;
while ($i <= count($dir_stack)-1)
{
	echo $dir_stack[$i].'<br>';
	if ($dir = opendir($dir_stack[$i]))
	{
		while (false !== ($file = readdir($dir)))
		{
			if ($file != "." && $file != ".." && false == is_dir($dir_stack[$i].$file))
			{
				unlink($dir_stack[$i].$file);
			}
			elseif ($file != "." && $file != "..")
			{
				array_push($dir_stack,$dir_stack[$i].$file.'/');
			}
		}
		closedir($dir);
	}
	$i++;
}
$i = count($dir_stack)-1;
while ($i >= 0)
{
	rmdir($dir_stack[$i]);
	$i--;
}
?>
 
Status
Not open for further replies.
Top