如何使用FileInfo类,避免使用PathTooLongException? [英] How can I use FileInfo class, avoiding PathTooLongException?

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

问题描述

如何使用(避免PathTooLongException):

How can I use (to avoid PathTooLongException):

System.IO.FileInfo

路径大于260个字符

是否有类似的类/方法返回FileInfo类的相同结果?

Are there similar classes/methods that return the same result of FileInfo class?

推荐答案

从我所知道的是不容易的。虽然可以使用phoenix提到的流的解决方法,但是文件名处理是不可能的。内部每个使用文件名的类可以执行长文件名的检查。

From what I know it is not easily possible. While it is possible to use workaround for streams as phoenix mentioned, it is not possible for file names handling. Internally every class that works with file names perform checks for long file names.

您可以实例化FileInfo并使用反射填充私有的memebers(但不推荐),并获取FileInfo指向长路径的文件。但是当您尝试使用此对象时,您仍然会收到PathTooLongException异常,因为例如,Path类(由FileInfo大量使用)会检查每个方法调用的长路径。

You can instantiate FileInfo and fill private memebers using reflection (however this is not recommended) and get FileInfo pointing to file with long path. But when you try to use this object you will still receive PathTooLongException exceptions, because for example, Path class (used heavily by FileInfo) checks for long path on every method call.

所以,只有一个正确的方法来获得无问题的长路径支持 - 实现你自己的一套类似于FileInfo行为的类。这不是很复杂(只有安全可能),但很耗时。

So, there is only one right way to get problem free long path support - implement your own set of classes that will mimic FileInfo behavior. It is not very complex (only security maybe), but time-consuming.

更新:这里甚至有两个可以解决这个问题的解决方案: a href =http://alphafs.codeplex.com/ =noreferrer> AlpfaFS 和 Zeta长途

Update: Here even two ready solutions for this problem: AlpfaFS and Zeta Long Paths

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

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