Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CFileHelper::removeDirectory() Does not always delete the directory! #3685

Closed
CyberPunkCodes opened this issue Dec 31, 2014 · 1 comment
Closed

Comments

@CyberPunkCodes
Copy link

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 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.

@CyberPunkCodes CyberPunkCodes changed the title Does not always delete the directory! CFileHelper::removeDirectory() Does not always delete the directory! Dec 31, 2014
@cebe cebe added this to the 1.1.17 milestone Dec 31, 2014
@CyberPunkCodes
Copy link
Author

@cebe A pull request has been created here: #3690

@samdark samdark modified the milestones: 1.1.17, 1.1.18 Dec 29, 2015
@samdark samdark modified the milestones: 1.1.19, 1.1.18 Feb 27, 2017
@samdark samdark closed this as completed Mar 13, 2017
@cebe cebe modified the milestone: 1.1.19 Apr 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants