开发者

How to iterate over long path names with any form of the Windows API

开发者 https://www.devze.com 2023-02-06 20:13 出处:网络
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 开发者_StackOverflow社区path.However, that doesn\'t sol

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 开发者_StackOverflow社区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.

0

精彩评论

暂无评论...
验证码 换一张
取 消