Automattic\WooCommerce\Blueprint
Util::delete_dir
Recursively delete a directory.
Method of the class: Util{}
No Hooks.
Returns
null. Nothing (null).
Usage
$result = Util::delete_dir( $dir_path );
- $dir_path(string) (required)
- The path to the directory.
Util::delete_dir() Util::delete dir code WC 10.8.1
public static function delete_dir( $dir_path ) {
if ( ! is_dir( $dir_path ) ) {
throw new \InvalidArgumentException( "$dir_path must be a directory" );
}
if ( substr( $dir_path, strlen( $dir_path ) - 1, 1 ) !== '/' ) {
$dir_path .= '/';
}
$files = glob( $dir_path . '*', GLOB_MARK );
foreach ( $files as $file ) {
if ( is_dir( $file ) ) {
static::delete_dir( $file );
} else {
// phpcs:ignore
unlink( $file );
}
}
// phpcs:ignore
rmdir( $dir_path );
}