/* 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 ()); //递归调用 } } }