QT中搜索文件列表
1.使用boost库
std::string query_path = "C:/Users/zx/Desktop/robots/config"; std::vector<std::string> file_name; boost::filesystem::directory_iterator end; for ( boost::filesystem::directory_iterator iter( query_path ); iter != end; iter++ ) { if ( boost::filesystem::is_regular_file( *iter ) ) { std::string log_file = iter->path().filename().string().data(); file_name.push_back( log_file ); } }
2.使用qt自身的库
const QString& mapPath = "C:/Users/zx/Desktop/robots/config"; QDir localDir( mapPath ); localDir.setNameFilters( QStringList() << "*.yaml" << "*.json" ); for ( QFileInfo fi : localDir.entryInfoList() ) { qDebug()<< fi.absoluteFilePath(); }