How to create a browse file dialog which can select files longer then MAX_PATH
-
I need a browse dialog that can select files that have file paths longer then _MAX_PATH(260). I've tried using GetOpenFileName, but I get a "File name is invalid" error when I select a file with a name longer then 260 (_MAX_PATH) characters. Does anyone have a method or know of an existing library/project that can display a browse dialog which can select file names longer then 260 characters?
Top ten member of C++ Expert Exchange. http://www.experts-exchange.com/Cplusplus
-
I need a browse dialog that can select files that have file paths longer then _MAX_PATH(260). I've tried using GetOpenFileName, but I get a "File name is invalid" error when I select a file with a name longer then 260 (_MAX_PATH) characters. Does anyone have a method or know of an existing library/project that can display a browse dialog which can select file names longer then 260 characters?
Top ten member of C++ Expert Exchange. http://www.experts-exchange.com/Cplusplus
Windows not support files longer than 259.
TCHAR lpstrFilename[MAX_PATH]="";
OPENFILENAME ofn;
CString pathname;
CString filename;
int nTerm=0;
char stemp[255]={0};
TCHAR *p;
memset(&ofn,0,sizeof(OPENFILENAME));
ofn.lStructSize=sizeof(OPENFILENAME);
ofn.lpstrFile=lpstrFilename;
ofn.hwndOwner=m_hWnd;
ofn.nMaxFile=MAX_PATH*2;
ofn.lpstrFilter="All files(*.*)\0*.*\0";
if(WINVER >= 0x0400)
ofn.Flags=OFN_ALLOWMULTISELECT|OFN_EXPLORER|OFN_LONGNAMES|OFN_FILEMUSTEXIST;
else ofn.Flags=OFN_FILEMUSTEXIST;
ofn.lpstrTitle="GetOpenFileName";
ofn.nFilterIndex=0;
if(GetOpenFileName(&ofn))
{
pathname=lpstrFilename;
if(pathname.Right(1)!="\\")pathname+="\\";
for(int i=0;;i++)
{
if(lpstrFilename[i]==0)
{
nTerm++;
if(lpstrFilename[i+1]==0)
{
if(nTerm==1)
m_FileList.AddString(lpstrFilename);
break;
}
else
{
p=&(lpstrFilename[i+1]);
strcpy(stemp,p);
m_FileList.AddString(pathname+stemp);
}
}
}
} -
I need a browse dialog that can select files that have file paths longer then _MAX_PATH(260). I've tried using GetOpenFileName, but I get a "File name is invalid" error when I select a file with a name longer then 260 (_MAX_PATH) characters. Does anyone have a method or know of an existing library/project that can display a browse dialog which can select file names longer then 260 characters?
Top ten member of C++ Expert Exchange. http://www.experts-exchange.com/Cplusplus
As KevinXli pointed out, make sure you pass large enough buffers and set the nMaxFilexxx members of the OPENFILENAME struct accordingly. Mark
Mark Salsbery Microsoft MVP - Visual C++ "Great job team! Head back to base for debriefing and cocktails."
-
Windows not support files longer than 259.
TCHAR lpstrFilename[MAX_PATH]="";
OPENFILENAME ofn;
CString pathname;
CString filename;
int nTerm=0;
char stemp[255]={0};
TCHAR *p;
memset(&ofn,0,sizeof(OPENFILENAME));
ofn.lStructSize=sizeof(OPENFILENAME);
ofn.lpstrFile=lpstrFilename;
ofn.hwndOwner=m_hWnd;
ofn.nMaxFile=MAX_PATH*2;
ofn.lpstrFilter="All files(*.*)\0*.*\0";
if(WINVER >= 0x0400)
ofn.Flags=OFN_ALLOWMULTISELECT|OFN_EXPLORER|OFN_LONGNAMES|OFN_FILEMUSTEXIST;
else ofn.Flags=OFN_FILEMUSTEXIST;
ofn.lpstrTitle="GetOpenFileName";
ofn.nFilterIndex=0;
if(GetOpenFileName(&ofn))
{
pathname=lpstrFilename;
if(pathname.Right(1)!="\\")pathname+="\\";
for(int i=0;;i++)
{
if(lpstrFilename[i]==0)
{
nTerm++;
if(lpstrFilename[i+1]==0)
{
if(nTerm==1)
m_FileList.AddString(lpstrFilename);
break;
}
else
{
p=&(lpstrFilename[i+1]);
strcpy(stemp,p);
m_FileList.AddString(pathname+stemp);
}
}
}
}Windows does support files longer then 259 characters, but you have to use a different syntax. You have to use prefix "\\?\" with the file name, and use CreateFile. For more information, look at CreateFile in MSDN. I've already tried using GetOpenFileName, and I gave it required buffer size which was greater then MAX_PATH, but it still failed.
Top ten member of C++ Expert Exchange. http://www.experts-exchange.com/Cplusplus
-
As KevinXli pointed out, make sure you pass large enough buffers and set the nMaxFilexxx members of the OPENFILENAME struct accordingly. Mark
Mark Salsbery Microsoft MVP - Visual C++ "Great job team! Head back to base for debriefing and cocktails."
I've already tried using GetOpenFileName, and I gave it required buffer size which was greater then MAX_PATH, but it still failed. Here's example code: void TestLongFileBrowse() { TCHAR acPath[2048] = _T("\0"); OPENFILENAME ofn; ZeroMemory(&ofn,sizeof(OPENFILENAME)); ofn.lStructSize = sizeof(OPENFILENAME); ofn.nMaxFile = 2048; ofn.lpstrFile = acPath; if (GetOpenFileName(&ofn)) { printf("Path length: %d\n", _tcslen(ofn.lpstrFile)); printf("Path: %S\n", ofn.lpstrFile); } else printf("CommDlgExtendedError(): %d\n"); }
Top ten member of C++ Expert Exchange. http://www.experts-exchange.com/Cplusplus
-
I've already tried using GetOpenFileName, and I gave it required buffer size which was greater then MAX_PATH, but it still failed. Here's example code: void TestLongFileBrowse() { TCHAR acPath[2048] = _T("\0"); OPENFILENAME ofn; ZeroMemory(&ofn,sizeof(OPENFILENAME)); ofn.lStructSize = sizeof(OPENFILENAME); ofn.nMaxFile = 2048; ofn.lpstrFile = acPath; if (GetOpenFileName(&ofn)) { printf("Path length: %d\n", _tcslen(ofn.lpstrFile)); printf("Path: %S\n", ofn.lpstrFile); } else printf("CommDlgExtendedError(): %d\n"); }
Top ten member of C++ Expert Exchange. http://www.experts-exchange.com/Cplusplus
Are you using the Unicode version of
GetOpenFileName()
? Only the Unicode APIs support full paths longer thanMAX_PATH
--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ Dunder-Mifflin, this is Pam.
-
Are you using the Unicode version of
GetOpenFileName()
? Only the Unicode APIs support full paths longer thanMAX_PATH
--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ Dunder-Mifflin, this is Pam.
I've tried it with both UNICODE and ANSI.
Top ten member of C++ Expert Exchange. http://www.experts-exchange.com/Cplusplus
-
I need a browse dialog that can select files that have file paths longer then _MAX_PATH(260). I've tried using GetOpenFileName, but I get a "File name is invalid" error when I select a file with a name longer then 260 (_MAX_PATH) characters. Does anyone have a method or know of an existing library/project that can display a browse dialog which can select file names longer then 260 characters?
Top ten member of C++ Expert Exchange. http://www.experts-exchange.com/Cplusplus
Axter wrote:
Non-existent page.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
I need a browse dialog that can select files that have file paths longer then _MAX_PATH(260). I've tried using GetOpenFileName, but I get a "File name is invalid" error when I select a file with a name longer then 260 (_MAX_PATH) characters. Does anyone have a method or know of an existing library/project that can display a browse dialog which can select file names longer then 260 characters?
Top ten member of C++ Expert Exchange. http://www.experts-exchange.com/Cplusplus
Axter wrote:
I've tried using GetOpenFileName, but I get a "File name is invalid" error...
Which is different than
FNERR_BUFFERTOOSMALL
.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne