c – WIN32_FIND_DATA – 获取绝对路径

前端之家收集整理的这篇文章主要介绍了c – WIN32_FIND_DATA – 获取绝对路径前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用这样的东西:
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 files
HANDLE 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 handle
FindClose(handle);

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

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

解决方法

原文链接:https://www.f2er.com/c/115440.html

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