Tools.php
public static function deleteDirectory($dirName, $deleteSelf = true)
    {
        $dirName = rtrim($dirName, '/') . '/';
        if (file_exists($dirName) && $files = scandir($dirName, SCANDIR_SORT_NONE)) {
            foreach ($files as $file) {
                if ($file !== '.' && $file !== '..' && $file !== '.svn') {
                    if (is_dir($dirName . $file)) {
                        self::deleteDirectory($dirName . $file, true);
                    } elseif (file_exists($dirName . $file)) {
                        @chmod($dirName . $file, 0777); // NT ?
                        unlink($dirName . $file);
                    }
                }
            }
            if ($deleteSelf && !rmdir($dirName)) {
                @chmod($dirName, 0777); // NT ?

                return false;
            }

            return true;
        }

        return false;
    }
public static function deleteDirectory($dirName, $deleteSelf = true)
    {
        $dirName = rtrim($dirName, '/') . '/';
        if (file_exists($dirName) && $files = scandir($dirName, SCANDIR_SORT_NONE)) {
            foreach ($files as $file) {
                if ($file !== '.' && $file !== '..' && $file !== '.svn') {
                    if (is_dir($dirName . $file)) {
                        self::deleteDirectory($dirName . $file, true);
                    } elseif (file_exists($dirName . $file)) {
                        @chmod($dirName . $file, 0777); // NT ?
                        unlink($dirName . $file);
                    }
                }
            }
            if ($deleteSelf && !rmdir($dirName)) {
                @chmod($dirName, 0777); // NT ?

                return false;
            }

            return true;
        }

        return false;
    }
Delete directory and subdirectories

@param string $dirName Directory name
@param bool $deleteSelf Delete also specified directory

@return bool