public static function removeEmptyDirectoriesOnPath(string $path, string $basePath = null)
    {
        if ($basePath !== null) {
            $basePath = rtrim($basePath, '/');
            if (strpos($path, $basePath) !== 0) {
                throw new FilesException(sprintf('Could not remove empty directories on path because the given base path "%s" is not a parent path of "%s".', $basePath, $path), 1323962907);
            }
        }
        foreach (array_reverse(explode('/', $path)) as $currentSegment) {
            if ($path === $basePath) {
                break;
            }
            if (file_exists($path . '/.DS_Store')) {
                @unlink($path . '/.DS_Store');
            }
            if (@rmdir($path) === false) {
                break;
            }
            $path = substr($path, 0, -(strlen($currentSegment) + 1));
        }
    }
public static function removeEmptyDirectoriesOnPath(string $path, string $basePath = null)
    {
        if ($basePath !== null) {
            $basePath = rtrim($basePath, '/');
            if (strpos($path, $basePath) !== 0) {
                throw new FilesException(sprintf('Could not remove empty directories on path because the given base path "%s" is not a parent path of "%s".', $basePath, $path), 1323962907);
            }
        }
        foreach (array_reverse(explode('/', $path)) as $currentSegment) {
            if ($path === $basePath) {
                break;
            }
            if (file_exists($path . '/.DS_Store')) {
                @unlink($path . '/.DS_Store');
            }
            if (@rmdir($path) === false) {
                break;
            }
            $path = substr($path, 0, -(strlen($currentSegment) + 1));
        }
    }
public static function removeEmptyDirectoriesOnPath ( string $ path , string $ basePath = null ) { if ( $ basePath !== null ) { $ basePath = rtrim ( $ basePath , '/' ) ; if ( strpos ( $ path , $ basePath ) !== 0 ) { throw new FilesException ( sprintf ( 'Could not remove empty directories on path because the given base path "%s" is not a parent path of "%s".' , $ basePath , $ path ) , 1323962907 ) ; } } foreach ( array_reverse ( explode ( '/' , $ path ) ) as $ currentSegment ) { if ( $ path === $ basePath ) { break ; } if ( file_exists ( $ path . '/.DS_Store' ) ) { @ unlink ( $ path . '/.DS_Store' ) ; } if ( @ rmdir ( $ path ) === false ) { break ; } $ path = substr ( $ path , 0 , - ( strlen ( $ currentSegment ) + 1 ) ) ; } }
Removes all empty directories on the specified path. If a base path is given, this function will not remove
directories, even if empty, above and including that base path.

Any .DS_Store files are silently removed.

@param string $path The path on which empty directories shall be removed
@param string $basePath A parent path of $path where removal of directories stops
@return void
@see removeDirectoryRecursively()
@api
@throws FilesException
Removes all empty directories on the specified path . If a base path is given this function will not remove directories even if empty above and including that base path .