In my VC++ application, I am selecting a couple of text files by invoking File Explorer and using the GetFileAttributesW()
API to retrieve file system attributes.
GetFileAttributesW()
is failing to process, reporting a ‘system does not find the file specified’ error.
I know it is, because the file name exceeds MAX_PATH
characters, which is 260 characters, but every file name count is less than 260 characters, and both of the file count exceeds 260 characters. Which means I have created 2 text files in the name of
erererererererertytytytytytytytyghjlmkjhnbvrevrnthgenothandbgelonhebgaqwebasdfghjklpoiuytrewqazsxdcfvgbhnjmklpoiuytrewqasdfghjklmnbvcxzasdfghjklpoiuytrewqasdfghjklmnbvcxzasdfghjklpoiuytrewqasdfghjk.txt
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbg.txt
and selected both of the files.
Kindly refer to the source code below and assist me on this.
CFileDialog fd(TRUE, NULL, NULL, OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_ALLOWMULTISELECT, NULL, CWnd::FromHandle(m_hWnd));
CString strTitle = L"test";
fd.m_ofn.lpstrTitle = (LPCTSTR)strTitle;
if (fd.DoModal() == IDOK)
{
POSITION pos = fd.GetStartPosition();
while (pos)
{
CString strFullPath(fd.GetNextPathName(pos));
DWORD dwAttr = ::GetFileAttributesW(strFullPath);
/// ////////////////////////////////////////////////////////////
DWORD errorMessageID = ::GetLastError();
LPSTR messageBuffer = nullptr;
size_t size = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, errorMessageID, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&messageBuffer, 0, NULL);
std::string message(messageBuffer, size);
LocalFree(messageBuffer);
///////////////////////////////////////////////////////////////
}
}