Created
January 28, 2023 23:15
-
-
Save rotexdegba/832c68a1b14b3d7a35771ed668b4a114 to your computer and use it in GitHub Desktop.
Recursive Directory Deletion PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function rmdirRecursive(string $dir) { | |
$iter = new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS); | |
$it = new RecursiveIteratorIterator($iter, RecursiveIteratorIterator::CHILD_FIRST); | |
foreach($it as $file) { | |
if ($file->isDir()) { | |
rmdir($file->getPathname()); | |
} else { | |
unlink($file->getPathname()); | |
} | |
} | |
rmdir($dir); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment