You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The current code does not always delete a directory recursively. In some cases, it deletes just the files. I am not sure exactly why, but I had a folder that this was failing to delete. After a little searching, I came across a nice, simple, elegant function that is pretty solid.
public static function removeDirectory($dir)
{
$files = array_diff(scandir($dir), array('.','..'));
foreach ($files as $file) {
(is_dir("$dir/$file")) ? self::removeDirectory("$dir/$file") : unlink("$dir/$file");
}
return rmdir($dir);
}
I purpose that we see if we can get some opinions on this, and possibly replace the current removeDirectory() function with this one.
The text was updated successfully, but these errors were encountered:
CyberPunkCodes
changed the title
Does not always delete the directory!
CFileHelper::removeDirectory() Does not always delete the directory!
Dec 31, 2014
The current code does not always delete a directory recursively. In some cases, it deletes just the files. I am not sure exactly why, but I had a folder that this was failing to delete. After a little searching, I came across a nice, simple, elegant function that is pretty solid.
I do not take credit for it, it was posted as a comment on php.net's docs: http://php.net/manual/en/function.rmdir.php named as delTree().
I purpose that we see if we can get some opinions on this, and possibly replace the current removeDirectory() function with this one.
The text was updated successfully, but these errors were encountered: