MFC 历遍一个目录下所有文件

    HANDLE hFile;
    WIN32_FIND_DATA fileinfo;
    DWORD errorcode = 0;
    CString  filename;
    hFile=FindFirstFile(_T("Storage Card\\*.*"),&fileinfo);
    while(hFile!=INVALID_HANDLE_VALUE&&errorcode!=ERROR_NO_MORE_FILES)
    {
      
      filename=fileinfo.cFileName;
      if(filename.Right(4)==_T(".dat"))
      {
         TRACE(filename+_T(";")+filename.Mid(3,2)+_T("\r\n"));

      }
      FindNextFile(hFile,&fileinfo);
      errorcode=GetLastError();
     
    }   
    if(errorcode==ERROR_NO_MORE_FILES)
    {
     
     TRACE(_T("检索结束"));;
    }
    CloseHandle(hFile);

 

posted on 2012-04-19 15:37  markygis  阅读(329)  评论(0编辑  收藏  举报