查找目录下的 xml 后缀的文件(例子)

来源:互联网 发布:地震讯息 软件 编辑:程序博客网 时间:2024/05/18 03:16

例子:查询 String_SimpChinese.xml ,把红色的字符截取出来

 

void CDlgMyBaseSet::ObtainLanName()
{
 CComboBox *m_LanBox = (CComboBox*)GetDlgItem(IDC_COMBO_LanName);
 //找到程序路径
 WCHAR szFile[MAX_PATH];
 GetModuleFileName(NULL,szFile,MAX_PATH);
 size_t i;
 for(i=wcslen(szFile)-1; i>0 && szFile[i]!='//'; i--);
 szFile[i]='/0';
 CString strExePath = szFile;

 CString strXmlFile =strExePath+"//*.xml";
 
    WIN32_FIND_DATA   FindFileData;
    HANDLE   hFile;
    hFile   =   FindFirstFile(strXmlFile,  &FindFileData);

 do{

  //获得语言名称
  CString strFileName;
  strFileName = FindFileData.cFileName;
  int nFirst = strFileName.Find('_', 0);
  if ((nFirst == -1) || (nFirst == 0))
  {
   continue;
  }
  int nEnd = strFileName.Find('.',nFirst+1);
  CString strLanName;
  strLanName = strFileName.Mid(nFirst+1,nEnd-nFirst-1);
  m_LanBox->AddString(strLanName);    
  
 }while(FindNextFile(hFile,&FindFileData));
 FindClose(hFile);
 hFile = NULL;
}