zoukankan      html  css  js  c++  java
  • QT 删除文件指定目录

     1 bool deleteDir(const QString &dirName)
     2 {
     3     QDir directory(dirName);
     4     if (!directory.exists())
     5     {
     6         return true;
     7     }
     8 
     9 
    10     QString srcPath = QDir::toNativeSeparators(dirName);
    11     if (!srcPath.endsWith(QDir::separator()))
    12         srcPath += QDir::separator();
    13 
    14 
    15     QStringList fileNames = directory.entryList(QDir::AllEntries | QDir::NoDotAndDotDot | QDir::Hidden);
    16     bool error = false;
    17     for (QStringList::size_type i=0; i != fileNames.size(); ++i)
    18     {
    19         QString filePath = srcPath + fileNames.at(i);
    20         QFileInfo fileInfo(filePath);
    21         if (fileInfo.isFile() || fileInfo.isSymLink())
    22         {
    23             QFile::setPermissions(filePath, QFile::WriteOwner);
    24             if (!QFile::remove(filePath))
    25             {
    26                 qDebug() << "remove file" << filePath << " faild!";
    27                 error = true;
    28             }
    29         }
    30         else if (fileInfo.isDir())
    31         {
    32             if (!deleteDir(filePath))
    33             {
    34                 error = true;
    35             }
    36         }
    37     }
    38 
    39 
    40     if (!directory.rmdir(QDir::toNativeSeparators(directory.path())))
    41     {
    42         qDebug() << "remove dir" << directory.path() << " faild!";
    43         error = true;
    44     }
    45     return !error;
    46 }
  • 相关阅读:
    iOS React Native实践系列二
    iOS React Native实践系列一
    ios各种兼容记录
    ios的__weak、__strong关键字
    index使用基本原则
    mysql explain详解
    手写迷你Tomcat
    动态代理
    C#设计模式(23种模式)
    unity 序列化和反序列化
  • 原文地址:https://www.cnblogs.com/felix-wang/p/6248317.html
Copyright © 2011-2022 走看看