Qt遍历目录及其所有子目录文件 返回文件绝对路径

复制代码
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;

        

}
复制代码

 

posted @   chyn  阅读(517)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
点击右上角即可分享
微信分享提示