public static function removeDir($dir)
    {
        if (is_dir($dir)) {
            $objects = scandir($dir);
            foreach ($objects as $object) {
                if ('.' != $object && '..' != $object) {
                    if ('dir' == filetype($dir . DS . $object)) {
                        static::removeDir($dir . DS . $object);
                    } else {
                        if (! unlink($dir . DS . $object)) {
                            throw new ErrorException(
                                'The following file could not be deleted: ' . $dir . DS . $object
                            );
                        }
                    }
                }
            }

            if (! rmdir($dir)) {
                throw new ErrorException("The following directory could not be deleted: {$dir}");
            }
        }
    }
public static function removeDir($dir)
    {
        if (is_dir($dir)) {
            $objects = scandir($dir);
            foreach ($objects as $object) {
                if ('.' != $object && '..' != $object) {
                    if ('dir' == filetype($dir . DS . $object)) {
                        static::removeDir($dir . DS . $object);
                    } else {
                        if (! unlink($dir . DS . $object)) {
                            throw new ErrorException(
                                'The following file could not be deleted: ' . $dir . DS . $object
                            );
                        }
                    }
                }
            }

            if (! rmdir($dir)) {
                throw new ErrorException("The following directory could not be deleted: {$dir}");
            }
        }
    }
public static function removeDir ( $ dir ) { if ( is_dir ( $ dir ) ) { $ objects = scandir ( $ dir ) ; foreach ( $ objects as $ object ) { if ( '.' != $ object && '..' != $ object ) { if ( 'dir' == filetype ( $ dir . DS . $ object ) ) { static :: removeDir ( $ dir . DS . $ object ) ; } else { if ( ! unlink ( $ dir . DS . $ object ) ) { throw new ErrorException ( 'The following file could not be deleted: ' . $ dir . DS . $ object ) ; } } } } if ( ! rmdir ( $ dir ) ) { throw new ErrorException ( "The following directory could not be deleted: {$dir}" ) ; } } }
Recursively remove a directory and all of it's contents

@param $dir

@throws ErrorException
Recursively remove a directory and all of it s contents