WP_CLI
Extractor::get_first_subfolder
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.
Returns
String. First subfolder, or same as $path if none found.
Usage
$result = Extractor::get_first_subfolder( $path );
- $path(string) (required)
- Path to find the first subfolder in.
Extractor::get_first_subfolder() Extractor::get first subfolder code WP-CLI 2.13.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;
}