Created
October 9, 2022 10:26
-
-
Save jleehr/809d0d7b1c00fb9c40deb78c949ffd8f to your computer and use it in GitHub Desktop.
Delete directory and files recursive
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 | |
$dir = __DIR__ . '/data/folder-to-delete'; | |
$it = new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS); | |
$files = new RecursiveIteratorIterator($it, | |
RecursiveIteratorIterator::CHILD_FIRST); | |
foreach($files as $file) { | |
if ($file->isDir()){ | |
rmdir($file->getRealPath()); | |
} else { | |
unlink($file->getRealPath()); | |
} | |
} | |
rmdir($dir); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment