Boost.Filesystem 中的 MAX_PATH 限制
我想使用 Boost.Filesystem 库来操作路径、文件和目录。 我的问题是是否支持比 MAX_PATH 长的路径?
我知道在 Win32API 中我们有解决方法“\\?\”,但 PathAppend 和 PathCombine 等基本函数不支持它。
所以我正在寻找有关 MAX_PATH 和 Boost.FS 的任何有用信息。
谢谢
UPD:我关心所有操作,如路径追加、路径组合等(我在 Win32API 中有这些函数,但它们不适用于长于 MAX_PATH 的路径) 例如,CreateFileW 和DeleteFileW 都支持长于MAX_PATH 的路径。 Boost.FS 可以替代 Win32API 实用函数,例如 shlwapi 和 shell32 中的函数,这些函数通常不支持长路径
I want to use Boost.Filesystem library to manipulate paths, files and directories.
My question is are paths longer than MAX_PATH supported?
I know that in Win32API we have workaround "\\?\" but it's not supported by basic functions like PathAppend and PathCombine.
So I'm looking for any useful info about MAX_PATH and Boost.FS.
Thanks
UPD: I care for all operation like path append, path combine, etc (I have those functions in Win32API, but they doesn't work with paths longer than MAX_PATH)
For example CreateFileW and DeleteFileW both support paths longer than MAX_PATH.
May Boost.FS be a replacement for Win32API utility functions such as those found in shlwapi and shell32 which often do not support long paths
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
事实上,Windows支持任意长度的路径,并且任何路径都可以在Windows上转换为字符串。在这种情况下需要添加
\\?\
,但这是“从给定路径生成字符串”操作的一部分。AFAIK,Boost::FileSystem 在 Windows 上做错了。
我不知道是否计划修复。请参阅此了解其应该如何完毕。
The truth is that Windows supports paths of any length, and any path can be converted to string on windows. Adding
\\?\
is required in such case, but this is the part of "make a string out of a given path" operation.AFAIK, Boost::FileSystem does this wrong on windows.
I do not know if a fix is planned. See this about how it should be done.
您可以使用或不使用 Boost.Filesystem 来操作任意长度的文件系统路径字符串。
MAX_PATH 是 Windows 文件 API 的限制。也就是说,您不能向 Windows API 传递太长的路径字符串。
例如,如果路径长度超过 MAX_PATH 长度,Boost.Filesystem 的删除功能将会失败。您希望 Boost.Filesystem 执行诸如更改当前目录并使用相对路径来防止 MAX_PATH 限制之类的操作吗?我不认为这是可能的。
已编辑
由于 Boost.Filesystem 是在 C++ 字符串上实现的,因此您无需担心路径长度。 Boost.Filesystem不仅提供路径字符串操作方法,还提供文件系统操作方法。如果生成的路径太长,您应该避免使用文件系统方法。
我不知道 Boost.Filesystem 是否支持 Win32 Unicode 路径,但您可以在调用 Win32 文件 API 之前将最终 ANSI 路径转换为 Unicode 路径。
You can manipulate any length of file system path string with or without Boost.Filesystem.
MAX_PATH is the restrictions of Windows File APIs. That is, you can not pass too long path string to Windows APIs.
For instance, remove function of the Boost.Filesystem will fail with longer than MAX_PATH length path. You want Boost.Filesystem to do something like change current directory and use relative path to prevent MAX_PATH restriction ? I don't think so its possible.
EDITED
Because Boost.Filesystem implemented upon C++ string, you don't need to worry about path length. Boost.Filesystem provide not only path string manipulation methods but also file system manipulation methods. You should avoid file system methods if the resulting path is too long.
I don't know whether or not Boost.Filesystem support Win32 Unicode path but you could convert final ANSI path to Unicode path before calling Win32 file APIs.