WP_CLI

Extractor::rmdir()public staticWP-CLI 1.0

Delete all files and directories recursively from directory. Directory must exist.

Method of the class: Extractor{}

No Hooks.

Return

null. Nothing.

Usage

$result = Extractor::rmdir( $dir );
$dir(string) (required)
-

Extractor::rmdir() code WP-CLI 2.8.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 );
}