c – WIN32_FIND_DATA – 获取绝对路径

前端之家收集整理的这篇文章主要介绍了c – WIN32_FIND_DATA – 获取绝对路径前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用这样的东西:
  1. std::string tempDirectory = "./test/*";
  2.  
  3. WIN32_FIND_DATA directoryHandle;
  4. memset(&directoryHandle,sizeof(WIN32_FIND_DATA));//perhaps redundant???
  5.  
  6. std::wstring wideString = std::wstring(tempDirectory.begin(),tempDirectory.end());
  7. LPCWSTR directoryPath = wideString.c_str();
  8.  
  9. //iterate over all files
  10. HANDLE handle = FindFirstFile(directoryPath,&directoryHandle);
  11. while(INVALID_HANDLE_VALUE != handle)
  12. {
  13. //skip non-files
  14. if (!(directoryHandle.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
  15. {
  16. //convert from WCHAR to std::string
  17. size_t size = wcslen(directoryHandle.cFileName);
  18. char * buffer = new char [2 * size + 2];
  19. wcstombs(buffer,directoryHandle.cFileName,2 * size + 2);
  20. std::string file(buffer);
  21. delete [] buffer;
  22.  
  23. std::cout << file;
  24. }
  25.  
  26. if(FALSE == FindNextFile(handle,&directoryHandle)) break;
  27. }
  28.  
  29. //close the handle
  30. FindClose(handle);

它在相对目录./test/*中打印每个文件名称.

有没有办法确定这个目录的绝对路径,就像Linux上的realpath()一样,不涉及像BOOST这样的第三方库?我想打印每个文件绝对路径.

解决方法

猜你在找的C&C++相关文章