我的服务器上有一些文件超出了 MAX_PATH 限制。
我多次听说您可以通过在路径前添加 \\?\ 来列出这些文件。但是,这并不能解决 FindFirstFile[Ex]
及其合作伙伴的问题,因为它们使用将文件名长度限制为 MAX_PATH
的数据结构。
是否有其他方法可以迭代目录结构以查找名称太长的文件?我见过一些实用程序可以做到这一点,但没有一个以源代码形式提供。
请注意,我已经看到了 .NET BCL 人员的博客文章,并点击了他们提供的链接。
为了简单起见,我更喜欢用 C 或 C++ 来完成此操作,但目前任何免费可用的语言都可以。
感谢指向代码、文档或任何有用的内容的指针。
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.
发布评论
评论(1)
我不认为这里有问题。您指的是
WIN32_FIND_DATA
确实返回长度限制为 MAX_PATH 的文件名。但由于这只是文件名部分,并且省略了路径,因此没有限制。在目录中,对象(文件或文件夹)的长度受到限制,通常为 255 个字符。您可以使用 lpMaximumComponentLength 参数确定此限制。 rel="noreferrer">
获取卷信息
。如果 Windows 中安装的任何卷的最大组件长度超过 255,我会感到惊讶。调用
FindFirstFile
接收一个以 null 结尾的字符串,lpFileName
指定目录和文件名(例如“*.85%29.aspx”)。 txt”,例如)进行搜索。文档指出: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 toMAX_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 ofGetVolumeInformation
. 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: