src/S3/StreamWrapper.php
private function deleteSubfolder($path, $params)
    {
        // Use a key that adds a trailing slash if needed.
        $prefix = rtrim($params['Key'], '/') . '/';
        $result = $this->getClient()->listObjects([
            'Bucket'  => $params['Bucket'],
            'Prefix'  => $prefix,
            'MaxKeys' => 1
        ]);

        // Check if the bucket contains keys other than the placeholder
        if ($contents = $result['Contents']) {
            return (count($contents) > 1 || $contents[0]['Key'] != $prefix)
                ? $this->triggerError('Subfolder is not empty')
                : $this->unlink(rtrim($path, '/') . '/');
        }

        return $result['CommonPrefixes']
            ? $this->triggerError('Subfolder contains nested folders')
            : true;
    }
private function deleteSubfolder($path, $params)
    {
        // Use a key that adds a trailing slash if needed.
        $prefix = rtrim($params['Key'], '/') . '/';
        $result = $this->getClient()->listObjects([
            'Bucket'  => $params['Bucket'],
            'Prefix'  => $prefix,
            'MaxKeys' => 1
        ]);

        // Check if the bucket contains keys other than the placeholder
        if ($contents = $result['Contents']) {
            return (count($contents) > 1 || $contents[0]['Key'] != $prefix)
                ? $this->triggerError('Subfolder is not empty')
                : $this->unlink(rtrim($path, '/') . '/');
        }

        return $result['CommonPrefixes']
            ? $this->triggerError('Subfolder contains nested folders')
            : true;
    }
private function deleteSubfolder ( $ path , $ params ) { // Use a key that adds a trailing slash if needed. $ prefix = rtrim ( $ params [ 'Key' ] , '/' ) . '/' ; $ result = $ this -> getClient ( ) -> listObjects ( [ 'Bucket' => $ params [ 'Bucket' ] , 'Prefix' => $ prefix , 'MaxKeys' => 1 ] ) ; // Check if the bucket contains keys other than the placeholder if ( $ contents = $ result [ 'Contents' ] ) { return ( count ( $ contents ) > 1 || $ contents [ 0 ] [ 'Key' ] != $ prefix ) ? $ this -> triggerError ( 'Subfolder is not empty' ) : $ this -> unlink ( rtrim ( $ path , '/' ) . '/' ) ; } return $ result [ 'CommonPrefixes' ] ? $ this -> triggerError ( 'Subfolder contains nested folders' ) : true ; }
Deletes a nested subfolder if it is empty.

@param string $path   Path that is being deleted (e.g., 's3://a/b/c')
@param array  $params A result of StreamWrapper::withPath()

@return bool
Deletes a nested subfolder if it is empty .