Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I make GetOpenFileName return paths longer than MAX_PATH?

Tags:

c++

winapi

mfc

I'm using the GetOpenFileName API, or in my case MFC's CFileDialog to open files, pretty much like it's shown here (except for a single file selection -- i.e. I provided my own longer buffer in m_ofn.lpstrFile.)

It works fine, except when a user picks a file whose path becomes longer than MAX_PATH - 1 (or 259) characters. In that case the following happens:

  • On my Windows 8.1, it converts the user selected path into an archaic 8.3 short file format: "C:\TESTDE~1\NEWFOL~1"

  • On Windows XP I can't even select anything, I get this:

enter image description here

So I'm curious, since the OS itself supports long Unicode paths, prefixed with \\?\ (including XP) is there any way to coax GetOpenFileName to return paths in that format as well and not be limited by 259 characters?

like image 763
c00000fd Avatar asked Jun 02 '14 07:06

c00000fd


People also ask

Does Windows file Explorer support long paths?

For example, Explorer won't let you create a folder name that ends up with a path that is longer than 260 characters and you can delete folders or files in folders that exceed the MAX_PATH limit. It's an inherent issue in Windows because the base Windows file APIs by default don't recognize these long paths.

What is long file path?

A file path is the total file name that consists of the local disk name, root folder name, names of folders/subfolders, file name, and file extension. A long path is the one that exceeds 260 characters.


1 Answers

Windows file dialogs, even the new Vista IFileDialog, will not return file names longer than MAX_PATH.

like image 141
David Heffernan Avatar answered Oct 04 '22 22:10

David Heffernan