I have some files on a server that exceed the MAX_PATH
limit.
I've repeatedly heard that you can list those files by pre-pending \\?\ to the path. However, that doesn't solve the problem with FindFirstFile[Ex]
and its partners as they use a data structure that limits file name length to MAX_PATH
.
Is there any other way to iterate over the directory structure to find the files that have a name that is too long? I've seen utilities that do it but none of them are available in source form.
Note that I have seen the blog entries from the .NET BCL folks and followed the links they provide.
I'd prefer to do this in C or C++ for simplicity but any freely available language will do for now.
Pointers to code, docs or anything useful are appreciated.
I don't think there's a problem here. You are referring to the WIN32_FIND_DATA
which does indeed return filenames limited in length to MAX_PATH
. But since this is only the filename part, and the path is omitted, there is no limitation.
Within a directory, an object (file or folder) is limited in length, typically to 255 characters. You can determine what this limit is with the lpMaximumComponentLength
parameter of GetVolumeInformation
. I'd be surprised if any volume mounted in Windows could have a maximum component length in excess of 255.
The call to FindFirstFile
receives a null-terminates string, lpFileName
which specifies the directory and filename (e.g. "*.txt", say) to search. The documentation states:
In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to 32,767 widecharacters, call the Unicode version of the function and prepend "\\?\" to the path.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With