QT遍历指定目录

时间:2022-12-24 12:39:28
/*
QT遍历指定目录
*/
#include <QDir>
void TraverseDirectory (QString Path) {
    QDir dir;
    dir. setPath (Path);

    QFileInfoList list = dir. entryInfoList ();
     for ( int i = 0 ; i < list. size (); ++ i) {
        QFileInfo fileInfo = list. at (i);
        
         if (fileInfo. isFile ()) {
             /*
            操作代码
            */
        }
         else {
             if (fileInfo. fileName () == "." || fileInfo. fileName () == ".." ) {
                 continue ;
            }
             TraverseDirectory (fileInfo. absoluteFilePath ()); //递归调用
        }
    }
}