c – WIN32_FIND_DATA – 获取绝对路径

c – WIN32_FIND_DATA – 获取绝对路径,第1张

概述我正在使用这样的东西: std::string tempDirectory = "./test/*";WIN32_FIND_DATA directoryHandle;memset(&directoryHandle, 0, sizeof(WIN32_FIND_DATA));//perhaps redundant???std::wstring wideString = std::wstrin 我正在使用这样的东西:
std::string tempDirectory = "./test/*";WIN32_FIND_DATA directoryHandle;memset(&directoryHandle,sizeof(WIN32_FIND_DATA));//perhaps redundant???std::wstring wIDeString = std::wstring(tempDirectory.begin(),tempDirectory.end());LPCWSTR directoryPath = wIDeString.c_str();//iterate over all filesHANDLE handle = FindFirstfile(directoryPath,&directoryHandle);while(INVALID_HANDLE_VALUE != handle){    //skip non-files    if (!(directoryHandle.DWfileAttributes & file_ATTRIBUTE_DIRECTORY))    {        //convert from WCHAR to std::string        size_t size = wcslen(directoryHandle.cfilename);        char * buffer = new char [2 * size + 2];        wcstombs(buffer,directoryHandle.cfilename,2 * size + 2);        std::string file(buffer);        delete [] buffer;        std::cout << file;    }    if(FALSE == FindNextfile(handle,&directoryHandle)) break;}//close the handleFindClose(handle);

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

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

解决方法 请参阅 GetFullPathName功能. 总结

以上是内存溢出为你收集整理的c – WIN32_FIND_DATA – 获取绝对路径全部内容,希望文章能够帮你解决c – WIN32_FIND_DATA – 获取绝对路径所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/1233047.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-06
下一篇2022-06-06

发表评论

登录后才能评论

评论列表(0条)

    保存