QString LeScienze500::getDvdPath() { #ifdef Q_WS_X11 QString path = "/media/LESCIENZE" ; QString path_1 = path + "/DVD1" ; QString path_2 = path + "/DVD2" ; if ( QFile().exists( path_1 ) || QFile().exists( path_2 ) ) return path ; else return QString() ; #endif #ifdef Q_WS_WIN QFileInfoList dev_list ; dev_list = QDir::drives() ; for ( QFileInfoList::iterator itr = dev_list.begin() ; itr < dev_list.end() ; itr++ ) { QString path = itr->absolutePath() ; QString path_1 = path + "/DVD1" ; QString path_2 = path + "/DVD2" ; if ( QFile().exists( path_1 ) || QFile().exists( path_2 ) ) { return path ; } } return QString() ; #endif }
bool PathManager::SearchDirContianSuffix(const QString &dirFrom, QStringList &result, QString &suffix) { QVector<QString> dirNames; QDir dir(dirFrom); QFileInfoList filst; QFileInfoList::iterator curFi; //初始化 dirNames.clear(); if (dir.exists()){ dirNames << dirFrom; } else{ return true; } //遍历各级文件夹,并将这些文件夹中的文件删除 for (int i = 0; i < dirNames.size(); ++i) { dir.setPath(dirNames[i]); filst = dir.entryInfoList(QDir::Dirs | QDir::Files | QDir::Readable | QDir::Writable | QDir::Hidden | QDir::NoDotAndDotDot , QDir::DirsFirst); if (filst.size()>0){ curFi = filst.begin(); while (curFi != filst.end()) { //遇到文件夹,则添加至文件夹列表dirs尾部 if (curFi->isDir()){ dirNames.push_back(curFi->filePath()); } else if (curFi->isFile()){ if (curFi->fileName().endsWith(suffix)){ result.push_back(curFi->absolutePath()); break; } } curFi++; }//end of while } } return true; }