-
-
Save janjouketjalsma/abe1e0eb3df74a9d501bdc21e6830eef to your computer and use it in GitHub Desktop.
PHP - Delete Files and Folders (wp directory)
This file contains hidden or 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 = '/path/to/folder'; | |
if ( is_dir( $dir ) ) { | |
$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 ); | |
} else { | |
echo 'Error: Path is not a valid directory.'; | |
} | |
echo 'Nuked That Directory.'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment