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

静远 2014-12-03 06:12:08
想要创建一个路径,由于文件夹的名字比较长,如果直接通过ForceDirectories函数创建的话,由于待创建的路径字符串长度已经超过255,会创建失败。不知道有没有其他什么函数可以创建呢?或者就是一级级去创建,比如路径为“D:\a\b\c\d”,先创建“D:\a\”这个路径,然后依次创建b、c、d的子路径,不知道这种方式是否可行?如果可行,该如何创建呢?谢谢!
...全文
230 点赞 收藏 6
写回复
6 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
武稀松 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
好象可以递归方式,逐层创建目录。
回复
发动态
发帖子
Windows SDK/API
创建于2007-08-02

1145

社区成员

Delphi Windows SDK/API
申请成为版主
社区公告
暂无公告