Ejemplo n.º 1
0
bool _removeDirectory(const QString &path) { // from http://stackoverflow.com/questions/2256945/removing-a-non-empty-directory-programmatically-in-c-or-c
    QByteArray pathRaw = path.toUtf8();
    DIR *d = opendir(pathRaw.constData());
    if (!d) return false;

    while (struct dirent *p = readdir(d)) {
        /* Skip the names "." and ".." as we don't want to recurse on them. */
        if (!strcmp(p->d_name, ".") || !strcmp(p->d_name, "..")) continue;

        QString fname = path + '/' + p->d_name;
        QByteArray fnameRaw = fname.toUtf8();
        struct stat statbuf;
        if (!stat(fnameRaw.constData(), &statbuf)) {
            if (S_ISDIR(statbuf.st_mode)) {
                if (!_removeDirectory(fname)) {
                    closedir(d);
                    return false;
                }
            } else {
                if (unlink(fnameRaw.constData())) {
                    closedir(d);
                    return false;
                }
            }
        }
    }
    closedir(d);

    return !rmdir(pathRaw.constData());
}
Ejemplo n.º 2
0
void PsUpdateDownloader::deleteDir(const QString &dir) {
    _removeDirectory(dir);
}
Ejemplo n.º 3
0
void psDeleteDir(const QString &dir) {
	_removeDirectory(dir);
}