当前位置:首页 > 算法相关 2020年03月14日
遍历目录及其所有子目录文件 返回文件绝对路径

QStringList MainWindow::getAllFile(QString Dirpath)

{

        qDebug()<<"entry Dir "<<Dirpath;

        QStringList filePathNames;

        QDir splDir(Dirpath);

        QFileInfoList fileInfoListInSplDir = splDir.entryInfoList(QDir::NoDotAndDotDot |QDir::Files | QDir::Dirs);

        QFileInfo tempFileInfo;

        for(int i=0;i<fileInfoListInSplDir.size();i++)

                {

                        tempFileInfo = fileInfoListInSplDir.at(i);

                        

                        if(tempFileInfo.isFile())

                                {

                                        qDebug()<<"file ";

                                        qDebug()<<tempFileInfo.absoluteFilePath();

                                        m_currentFileList << tempFileInfo.absoluteFilePath();

                                }

                        else if(tempFileInfo.isDir())

                                {

                                        qDebug()<<"dir ";

                                        qDebug()<<tempFileInfo.absoluteFilePath();

                                        filePathNames << getAllFile(tempFileInfo.absoluteFilePath());

                                }

                        else{

                                        qDebug()<<"nothing ";

                                        qDebug()<<tempFileInfo.fileName();

                                }

                }

        

        return filePathNames;

        

}



发表评论: