Windows 遍歷查找文件夾文件

代碼ide

int IteratorFileNameOfDir(char* pDirName)
{
 WIN32_FIND_DATAA struFindData;
 HANDLE hFileHandle;string

 char szFilePathName[1024] = { 0 };
 strcpy(szFilePathName, pDirName);
 strcat(szFilePathName, "\\*.*");
 hFileHandle = ::FindFirstFileA(szFilePathName, &struFindData);
 if (INVALID_HANDLE_VALUE == hFileHandle)
 {
  std::cout << "iterator file name failed" << std::endl;
  return -1;
 }
 while (::FindNextFileA(hFileHandle, &struFindData))
 {
  //排查父節點和指向當前的子節點
  if (
   (strcmp(struFindData.cFileName, ".") == 0) ||
   (strcmp(struFindData.cFileName, "..") == 0))
  {
   continue;
  }
  std::cout << struFindData.cFileName << std::endl;
  sprintf(szFilePathName, "%s/%s", pDirName, struFindData.cFileName);
  std::string strFileName = szFilePathName;
  //循環迭代
  if (struFindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
  {
   IteratorFileNameOfDir(szFilePathName);
  }
 }
 return 0;
}it

調用邏輯io

 char szDirName[] = "F:/opensource/osg/Production_3";
 IteratorFileNameOfDir(szDirName);class

相關文章
相關標籤/搜索