static public function removeRecursive( $directory )
    {
        $sourceDir = realpath( $directory );
        if ( !$sourceDir )
        {
            throw new ezcBaseFileNotFoundException( $directory, 'directory' );
        }
        $d = @dir( $sourceDir );
        if ( !$d )
        {
            throw new ezcBaseFilePermissionException( $directory, ezcBaseFileException::READ );
        }
        // check if we can remove the dir
        $parentDir = realpath( $directory . DIRECTORY_SEPARATOR . '..' );
        if ( !is_writable( $parentDir ) )
        {
            throw new ezcBaseFilePermissionException( $parentDir, ezcBaseFileException::WRITE );
        }
        // loop over contents
        while ( ( $entry = $d->read() ) !== false )
        {
            if ( $entry == '.' || $entry == '..' )
            {
                continue;
            }

            if ( is_dir( $sourceDir . DIRECTORY_SEPARATOR . $entry ) )
            {
                self::removeRecursive( $sourceDir . DIRECTORY_SEPARATOR . $entry );
            }
            else
            {
                if ( @unlink( $sourceDir . DIRECTORY_SEPARATOR . $entry ) === false )
                {
                    throw new ezcBaseFilePermissionException( $directory . DIRECTORY_SEPARATOR . $entry, ezcBaseFileException::REMOVE );
                }
            }
        }
        $d->close();
        rmdir( $sourceDir );
    }
static public function removeRecursive( $directory )
    {
        $sourceDir = realpath( $directory );
        if ( !$sourceDir )
        {
            throw new ezcBaseFileNotFoundException( $directory, 'directory' );
        }
        $d = @dir( $sourceDir );
        if ( !$d )
        {
            throw new ezcBaseFilePermissionException( $directory, ezcBaseFileException::READ );
        }
        // check if we can remove the dir
        $parentDir = realpath( $directory . DIRECTORY_SEPARATOR . '..' );
        if ( !is_writable( $parentDir ) )
        {
            throw new ezcBaseFilePermissionException( $parentDir, ezcBaseFileException::WRITE );
        }
        // loop over contents
        while ( ( $entry = $d->read() ) !== false )
        {
            if ( $entry == '.' || $entry == '..' )
            {
                continue;
            }

            if ( is_dir( $sourceDir . DIRECTORY_SEPARATOR . $entry ) )
            {
                self::removeRecursive( $sourceDir . DIRECTORY_SEPARATOR . $entry );
            }
            else
            {
                if ( @unlink( $sourceDir . DIRECTORY_SEPARATOR . $entry ) === false )
                {
                    throw new ezcBaseFilePermissionException( $directory . DIRECTORY_SEPARATOR . $entry, ezcBaseFileException::REMOVE );
                }
            }
        }
        $d->close();
        rmdir( $sourceDir );
    }
static public function removeRecursive ( $ directory ) { $ sourceDir = realpath ( $ directory ) ; if ( ! $ sourceDir ) { throw new ezcBaseFileNotFoundException ( $ directory , 'directory' ) ; } $ d = @ dir ( $ sourceDir ) ; if ( ! $ d ) { throw new ezcBaseFilePermissionException ( $ directory , ezcBaseFileException :: READ ) ; } // check if we can remove the dir $ parentDir = realpath ( $ directory . DIRECTORY_SEPARATOR . '..' ) ; if ( ! is_writable ( $ parentDir ) ) { throw new ezcBaseFilePermissionException ( $ parentDir , ezcBaseFileException :: WRITE ) ; } // loop over contents while ( ( $ entry = $ d -> read ( ) ) !== false ) { if ( $ entry == '.' || $ entry == '..' ) { continue ; } if ( is_dir ( $ sourceDir . DIRECTORY_SEPARATOR . $ entry ) ) { self :: removeRecursive ( $ sourceDir . DIRECTORY_SEPARATOR . $ entry ) ; } else { if ( @ unlink ( $ sourceDir . DIRECTORY_SEPARATOR . $ entry ) === false ) { throw new ezcBaseFilePermissionException ( $ directory . DIRECTORY_SEPARATOR . $ entry , ezcBaseFileException :: REMOVE ) ; } } } $ d -> close ( ) ; rmdir ( $ sourceDir ) ; }
Removes files and directories recursively from a file system

This method recursively removes the $directory and all its contents.
You should be <b>extremely</b> careful with this method as it has the
potential to erase everything that the current user has access to.

@param string $directory
Removes files and directories recursively from a file system