Extractor::get_first_subfolder()private staticWP-CLI 1.0

Return the first subfolder within a given path.

Falls back to the provided path if no subfolder was detected.

Method of the class: Extractor{}

No Hooks.


String. First subfolder, or same as $path if none found.


$result = Extractor::get_first_subfolder( $path );
$path(string) (required)
Path to find the first subfolder in.

Extractor::get_first_subfolder() code WP-CLI 2.8.0-alpha

private static function get_first_subfolder( $path ) {
	$iterator = new DirectoryIterator( $path );

	foreach ( $iterator as $fileinfo ) {
		if ( $fileinfo->isDir() && ! $fileinfo->isDot() ) {
			return "{$path}/{$fileinfo->getFilename()}";

	return $path;