public static function remove($path)
    {
        $removed = 0;

        if (file_exists($path)) {
            if (is_dir($path)) {
                if (false === ($handle = @opendir($path))) {
                    throw PathException::createUsingLastError();
                }

                while (false !== ($item = readdir($handle))) {
                    if (('.' === $item) || ('..' === $item)) {
                        continue;
                    }

                    $removed += self::remove($path . DIRECTORY_SEPARATOR . $item);
                }

                closedir($handle);

                if (!@rmdir($path)) {
                    throw PathException::createUsingLastError();
                }
            } elseif (!@unlink($path)) {
                throw PathException::createUsingLastError();
            }

            $removed++;
        }

        return $removed;
    }
public static function remove($path)
    {
        $removed = 0;

        if (file_exists($path)) {
            if (is_dir($path)) {
                if (false === ($handle = @opendir($path))) {
                    throw PathException::createUsingLastError();
                }

                while (false !== ($item = readdir($handle))) {
                    if (('.' === $item) || ('..' === $item)) {
                        continue;
                    }

                    $removed += self::remove($path . DIRECTORY_SEPARATOR . $item);
                }

                closedir($handle);

                if (!@rmdir($path)) {
                    throw PathException::createUsingLastError();
                }
            } elseif (!@unlink($path)) {
                throw PathException::createUsingLastError();
            }

            $removed++;
        }

        return $removed;
    }
public static function remove ( $ path ) { $ removed = 0 ; if ( file_exists ( $ path ) ) { if ( is_dir ( $ path ) ) { if ( false === ( $ handle = @ opendir ( $ path ) ) ) { throw PathException :: createUsingLastError ( ) ; } while ( false !== ( $ item = readdir ( $ handle ) ) ) { if ( ( '.' === $ item ) || ( '..' === $ item ) ) { continue ; } $ removed += self :: remove ( $ path . DIRECTORY_SEPARATOR . $ item ) ; } closedir ( $ handle ) ; if ( ! @ rmdir ( $ path ) ) { throw PathException :: createUsingLastError ( ) ; } } elseif ( ! @ unlink ( $ path ) ) { throw PathException :: createUsingLastError ( ) ; } $ removed ++ ; } return $ removed ; }
Recursively removes a file system path.

@param string $path The path to remove.

@return integer The number of paths removed.

@throws Exception
@throws PathException If the path could not be removed.
Recursively removes a file system path .