使用扩展长度路径安全吗?
我刚刚在 MSDN 上偶然发现这篇文章表示路径可以是 259 个字符 + NUL 终止符,但如果您使用“\\?\”作为前缀,WinAPI 允许您使用
最大总路径长度为 32,767 个字符。
渴望看到它工作,我尝试使用资源管理器中的前缀(在 XP SP3 上),但它根本不起作用(在任何路径上)。如果您将 \\?\C:\Path\to\an\existing.file
放在资源管理器的栏上,它将给出“文件未找到”错误。
所以我很困惑。我可以为(非古代)Windows 编写一些代码,以充分利用 NTFS 上提到的路径大小吗?为什么资源管理器不使用它?
I just stumbled on this article on MSDN that says a path can be 259 characters + NUL termination, but if you prefix it with "\\?\" WinAPI allows you to use the
maximum total path length of 32,767 characters.
Eager to see it working I tried using that prefix from Explorer (On XP SP3) but it doesn't work at all (on any path). If you put \\?\C:\Path\to\an\existing.file
on explorer's bar, it will give the "file not found" error.
So I'm confused. Can I code something for (non-ancient) Windows that makes full use of the mentioned path size on NTFS? Why Explorer doesn't use it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
有一组 API 调用可以与扩展路径一起使用,而有些则不能。 MSDN 通常都会提到这一点。
并不是说,如果您只是在 xp 下将该路径键入到 Windows 资源管理器中,则这不起作用,因为扩展路径语法只是 WIn32 API 的转义序列,而不是 Windows 资源管理器。现在,在 Win7 中这确实有效,因为很多人都期望它能有效。
另外,对于长路径,如果您更改工作目录或以子目录作为根打开资源管理器,它确实会有所帮助。
There is a SET of API calls that are work with extened-paths and some that do not. The MSDN usually mentions this.
Not that if you just type that path into windows explorerunder xp this does not work, because the extened path syntax is just an escape sequence for the WIn32 API and not for windows explorer. Now, In Win7 this does work because many people expected this to work.
Also for long paths, it does help if you change the working directory or open up explorer with a sub-directory as a root.
在有人告诉我 RTFM 之前...
其次,这让我想知道是否有可能通过使用非法文件名从资源管理器中隐藏文件(或查找此类文件)。
Before someone tells me to RTFM...
On a secondary note, this makes me wonder about the possibilities of hiding files (or finding such files) from explorer by using illegal file names.
您是在问为什么 Windows 中的所有组件都不支持它,还是在问使用这些长路径是否合法?
您绝对可以安全地使用它们,但您可能会激怒那些想要使用资源管理器等工具来浏览它们的人。我们在野外经常看到这样的路径。有时,当人们无法使用 MY_FAVORITE_TOOL 删除它时,他们会感到非常惊讶......
Are you asking why all components in Windows do not support it, or are you asking whether it's legal to use these long paths?
You can definitely safely use them, but you may irritate someone who wants to use tools like Explorer to browse them. We see paths like this all the time in the wild. Sometimes people are pretty surprised when they can't use MY_FAVORITE_TOOL to delete it...