如何避免System.IO.PathTooLongException? [英] How to avoid System.IO.PathTooLongException?

查看:1008
本文介绍了如何避免System.IO.PathTooLongException?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们经常碰到这个问题...

We constantly run into this problem...

例如:

如果我有,我想将它复制到另一个目录或UNC共享,如果路径的长度超过248(如果我没有记错),然后将其抛出PathTooLongException文件。有没有解决此问题的?

if I have a file that I want to copy it into an another directory or UNC share and if the length of the path exceeds 248 (if I am not mistaken), then it throws PathTooLongException. Is there any workaround to this problem?

PS:有没有注册表设置来设置此路径为字符集长

PS: Is there any registry setting to set this path to a longer char set?

推荐答案

本已深入讨论了BCL团队,请参阅<一href="http://blogs.msdn.com/bclteam/archive/2007/02/13/long-paths-in-net-part-1-of-3-kim-hamilton.aspx">blog项

This has been discussed in depth by the BCL team, see the blog entries

在本质上是没有办法做到这一点的在.NET code 的,并坚持到BCL。太多的功能依赖于能够规范化的路径名(其中立即触发功能的使用预期MAX_PATH要服从)。

In essence there is no way to do this within .Net code and stick to the BCL. Too many functions rely on being able to canonicalize the path name (which immediately triggers the use of functions expecting MAX_PATH to be obeyed).

您可以包装所有支持\\?\语法的Win32函数,有了这些,你就能够实现一套长的道路意识到功能,但这样做很麻烦。

You could wrap all the win32 functions that support the "\\?\" syntax, with these you would be able to implement a suite of long path aware functionality but this would be cumbersome.

由于工具的广大(包括浏览器[1])不能处理长路径名是不可取的,除非你是高兴的所有的使用所产生的文件系统交互经历往下走这条路线您的图书馆(或说是用来处理像的Robocopy工具数量有限)

Since a vast number of tools (including explorer[1]) cannot handle long path names it is inadvisable to go down this route unless you are happy that all interaction with the resulting file system goes through your library (or the limited number of tools that are built to handle it like robocopy)

在回答您的具体需要我会调查使用的Robocopy是否直接将足以执行此任务。

In answer to your specific need I would investigate whether the use of robocopy directly would be sufficient to perform this task.

[1] Vista的方式与引擎盖下的一些花哨的重命名缓解这个问题,但这个是脆弱的最好)

[1] Vista has ways to mitigate the issue with some fancy renaming under the hood but this is fragile at best)

这篇关于如何避免System.IO.PathTooLongException?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆