下面代码的目的是获取TargetDir(某一特定目录)下的所有后缀为“stl”的文件的名称列表:
void GetStlFileNameList( QDir Dir ,QFileInfoList &FileList)
{
QFileInfoList subFileList = Dir.entryInfoList(QDir::Files|QDir::CaseSensitive);//过滤条件为只限文件并区分大小写
for (int i = 0;i < subFileList.size(); i++)
{
QString suffix = subFileList[i].suffix();//获取后缀名
if (suffix.compare("stl") == 0)
{
FileList.push_back(subFileList[i]);
}
}
}
以下是调用代码示例
QString NailsDirectory = ImplantDirectory+ QDir::separator() + kImplantNails;
QDir NailsDir(NailsDirectory);
if(NailsDir.exists())
{
QFileInfoList NailsFileList;
GetImplantStlFileNameList(NailsDir,NailsFileList);
}