Remove a directory and its files.
beans_remove_dir( string $dir_path )
Return: (bool) Will always return true.
Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
$dir_path | string | true | - | Path to directory to remove. |
Source
function beans_remove_dir( $dir_path ) {
if ( ! is_dir( $dir_path ) ) {
return false;
}
$items = scandir( $dir_path );
unset( $items[0], $items[1] );
foreach ( $items as $needle => $item ) {
$path = $dir_path . '/' . $item;
if ( 'dir' === filetype( $dir_path . '/' . $item ) ) {
beans_remove_dir( $path );
} else {
@unlink( $path );
}
unset( $items[ $needle ] );
}
@rmdir( $dir_path );
return true;
}