-
-
Save drajathasan/4f8efd710fc4dcd6eb3ab31a8d1a97f5 to your computer and use it in GitHub Desktop.
PHP recursive rmdir
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 | |
/** | |
* Recursively empty and delete a directory | |
* | |
* @param string $path | |
* @ref https://gist.github.com/jmwebservices/986d9b975eb4deafcb5e2415665f8877 | |
*/ | |
function rrmdir( string $path ) : void | |
{ | |
if( trim( pathinfo( $path, PATHINFO_BASENAME ), '.' ) === '' ) | |
return; | |
if( is_dir( $path ) ) | |
{ | |
array_map( 'rrmdir', glob( $path . DIRECTORY_SEPARATOR . '{,.}*', GLOB_BRACE | GLOB_NOSORT ) ); | |
@rmdir( $path ); | |
} | |
else | |
@unlink( $path ); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment