QT讀取路徑及刪除指定路徑操作

1、程序界面如下:

2、程序代碼如下:

void Widget::on_pushButton_clicked()
{
    /// 讀取路徑
    QString path = ui->lineEdit->text();
    if (path == QString(""))
    {
        QMessageBox::warning(this,tr("警告"),tr("路徑爲空"),QMessageBox::Yes);
    }

    deleteSpecifiedPath(path);
}

void Widget::deleteSpecifiedPath(QString path)
{
    QStringList dirPaths;
    QDir splDir(path);
    QFileInfoList fileInfoListInSplDir = splDir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot);
    QFileInfo tempFileInfo;
    foreach (tempFileInfo, fileInfoListInSplDir)
    {
        QString file_name = tempFileInfo.fileName();
        if ((file_name == QString(".")) || (file_name == QString("..")))
        {
            continue;
        }

        dirPaths << tempFileInfo.absoluteFilePath();
    }

    for (int i = 0; i < dirPaths.size(); ++i)
    {
        qDebug()<<dirPaths.at(i)<<endl;
        QString file_path = dirPaths.at(i);
        if (file_path.contains(".svn", Qt::CaseSensitive))
        {
            qDebug()<<"delete"<<endl;
            splDir.rmpath(file_path);  /// 刪除路徑
        }
        else
        {
            deleteSpecifiedPath(file_path);
        }
    }
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章