WP_CLI
Extractor::rmdir
Delete all files and directories recursively from directory. Directory must exist.
Method of the class: Extractor{}
No Hooks.
Returns
null. Nothing (null).
Usage
$result = Extractor::rmdir( $dir );
- $dir(string) (required)
- .
Extractor::rmdir() Extractor::rmdir code WP-CLI 2.13.0-alpha
public static function rmdir( $dir ) {
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator(
$dir,
RecursiveDirectoryIterator::SKIP_DOTS
),
RecursiveIteratorIterator::CHILD_FIRST
);
foreach ( $files as $fileinfo ) {
$todo = $fileinfo->isDir() ? 'rmdir' : 'unlink';
$path = $fileinfo->getRealPath();
if ( 0 !== strpos( $path, $fileinfo->getRealPath() ) ) {
WP_CLI::warning(
"Temporary file or folder to be removed was found outside of temporary folder, aborting removal: '{$path}'"
);
}
$todo( $path );
}
rmdir( $dir );
}