C++ windows遍历目录

bool Search(TCHAR *Path,TCHAR *File)
{
 HANDLE hFind;
 WIN32_FIND_DATA wfd;
 ZeroMemory(&wfd,sizeof(WIN32_FIND_DATA));
 TCHAR PathTemp[512];
 memset(PathTemp,0,sizeof(PathTemp));
 wsprintf(PathTemp,L"%s\\*",Path);
 
 
 hFind=FindFirstFile(PathTemp,&wfd);
 if(INVALID_HANDLE_VALUE==hFind)
 {
  goto End;
 }
 do
 {
  if('.'==wfd.cFileName[0]){
   continue;
  }

  if(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
  {
   wsprintf(PathTemp,L"%s\\%s",Path,wfd.cFileName);
   Search(PathTemp,File);
  }
  else
  {
   WCHAR PathTemp1[128]={0};
   wsprintf(PathTemp1,L"%s\\%s",Path,wfd.cFileName);
   OutputDebugString(PathTemp1);
  }
 }while(FindNextFile(hFind,&wfd));

End: 
 FindClose(hFind);
 return true;
}

 

 

//调用

CString Tmp(L"C:\\test");
Search(Tmp.GetBuffer(),L"b.txt");

 

你可能感兴趣的:(windows)