Qt 打印目录和目录下的文件名

2020-02-21  本文已影响0人  Caiaolun
    QString stPath = "../../data";
    QDir dir(stPath);
    QStringList nameFilters;
    nameFilters<< "*.jpg" << "*.png";

    //QDir::Dirs: find directory
    //QDir::Readable find is read files
    //QDir::NoDotAndDotDot not find . and ..
    //QDir::Name Name sort
    QStringList stBranchPath = dir.entryList(QDir::Dirs|QDir::Readable|QDir::NoDotAndDotDot, QDir::Name);
    if(stBranchPath.isEmpty())
        qDebug("directorys are mpty");
    else
    {
        for(int i = 0; i < stBranchPath.size(); i++)
        {
            QString tem = stBranchPath.at(i);
            qDebug()<<"stBranchPath: "<<dir.filePath(tem);

            QDir stDir(dir.filePath(tem));
            //nameFilters just find *.jpg and *.png
            //QDir::Files: find Files
            //QDir::Readable find is read files
            //QDir::NoDotAndDotDot not find . and ..
            //QDir::Name Name sort
            QStringList stFileList = stDir.entryList(nameFilters, QDir::Files|QDir::Readable|QDir::NoDotAndDotDot, QDir::Name);
            if(stFileList.isEmpty())
                qDebug("files are mpty");
            else
            {
                for(int i = 0; i < stFileList.size(); i++)
                {
                    QString tem = stFileList.at(i);
                    qDebug()<<"BranchPath fileName: "<<tem;
                }
            }

        }
    }
上一篇 下一篇

猜你喜欢

热点阅读