I am using something like this:
std::string tempDirectory = "./test/*"; WIN32_FIND_DATA directoryHandle; memset(&directoryHandle, 0, 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);
which prints the names of each file in the relative ./test/* directory.
Is there a way to determine the absolute path of this directory, just as realpath() does on Linux without involving any third-party libraries like BOOST? I would like to print the absolute path to each file.
source share