请教关于创建文件路径的问题

静远 2014-12-03 06:12:08
想要创建一个路径,由于文件夹的名字比较长,如果直接通过ForceDirectories函数创建的话,由于待创建的路径字符串长度已经超过255,会创建失败。不知道有没有其他什么函数可以创建呢?或者就是一级级去创建,比如路径为“D:\a\b\c\d”,先创建“D:\a\”这个路径,然后依次创建b、c、d的子路径,不知道这种方式是否可行?如果可行,该如何创建呢?谢谢!
...全文
295 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
武稀松 2014-12-06
  • 打赏
  • 举报
回复
Windows的限制,你手动创建超过255长度的也会出问题
浩南_哥 2014-12-04
  • 打赏
  • 举报
回复
这是MSDN上关于路径的描述: Maximum Path Length In the Windows API, the maximum length for a path is MAX_PATH, which is defined as 260 characters . A path is structured in the following order: drive letter, colon, backslash, components separated by backslashes, and a null-terminating character, for example, the maximum path on the D drive is D:\<256 chars>NUL. Note Functions in the Windows API convert "/" to "\" as part of converting the name to an NT style name. The Unicode versions of several functions permit a maximum path length of approximately 32,000 characters composed of components up to 255 characters in length. To specify that kind of path, use the "\\?\" prefix. Note The maximum path of 32,000 characters is approximate, because the "\\?\" prefix can be expanded to a longer string, and the expansion applies to the total length. For example, "\\?\D:\<path>". To specify such a UNC path, use the "\\?\UNC\" prefix. For example, "\\?\UNC\<server>\<share>". These prefixes are not used as part of the path itself. They indicate that the path should be passed to the system with minimal modification, which means that you cannot use forward slashes to represent path separators, or a period to represent the current directory. Also, you cannot use the "\\?\" prefix with a relative path. Relative paths are limited to MAX_PATH characters. When using the API to create a directory, the specified path cannot be so long that you cannot not append an 8.3 file name. The shell and the file system may have different requirements. It is possible to create a path with the API that the shell UI cannot handle.
静远 2014-12-04
  • 打赏
  • 举报
回复
引用 3 楼 suiyunonghen 的回复:
ForceDirectories函数,路径超过255个字符就不行了?这个我到没注意过哦,果真?
嗯,超过255会提示超长
不得闲 2014-12-04
  • 打赏
  • 举报
回复
ForceDirectories函数,路径超过255个字符就不行了?这个我到没注意过哦,果真?
静远 2014-12-04
  • 打赏
  • 举报
回复
引用 1 楼 lyhoo163 的回复:
好象可以递归方式,逐层创建目录。
没有找到相关的处理函数,不知道该如何递归创建呢?
lyhoo163 2014-12-03
  • 打赏
  • 举报
回复
好象可以递归方式,逐层创建目录。

1,183

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧