有什么方法可以解决FileSystemInfo.Fullname有时抛出的PathTooLongException的问题? [英] Any way to work around the PathTooLongException that FileSystemInfo.Fullname throws sometimes?

查看:68
本文介绍了有什么方法可以解决FileSystemInfo.Fullname有时抛出的PathTooLongException的问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我访问 FileSystemInfo 对象的 Fullname 属性时,硬盘驱动器上的文件会抛出 PathTooLongException .有什么办法解决(不包括重命名文件,这不是一种选择)吗?

I have files on my hard drive that throw a PathTooLongException when I access the Fullname property of a FileSystemInfo object. Is there any way around this (excluding renaming the files which is not an option)?

http://msdn.microsoft其他答案提到的.com/zh-CN/library/aa365247%28VS.85%29.aspx#maxpath 建议在文件名上加上"\?\"前缀,但在这种情况下,是 DirectoryInfo.GetFileSystemInfos()负责创建 FileSystemInfo 对象,并且 DirectoryInfo 不接受该前缀,因此无法使用它.

http://msdn.microsoft.com/en-us/library/aa365247%28VS.85%29.aspx#maxpath mentioned by other answers suggests putting a "\?\" prefix on the file name but in this case the DirectoryInfo.GetFileSystemInfos() is responsible for creating the FileSystemInfo objects and DirectoryInfo doesn't accept that prefix so there's no way to use it.

答案" C#代码中的PathTooLongException "无济于事,因为这是一个多线程应用程序,我无法继续更改当前应用程序路径.

The answer " PathTooLongException in C# code " doesn't help because this is a multi-threaded application and I can't keep changing the current application path.

我真的必须使用 PInvoke 来做所有事情,才能读取硬盘上的每个文件吗?

Do I really have to do everything with PInvoke just to be able to read every file on the hard drive?

推荐答案

这看起来很有趣... Codeplex长途包装机

This looks interesting ... Codeplex Long Path Wrapper

长路径包装程序提供的功能使其可以更轻松地使用比System.IO名称空间的当前259个字符限制长的路径.使用长路径类,项目现在可以使用最多32,000个字符的路径.

The long path wrapper provides functionality to make it easier to work with paths that are longer than the current 259 character limit of the System.IO namespace. Using the long path classes, projects can now use paths up to 32,000 characters.

我会尝试一下,尽管我立即注意到它没有提供与 DirectoryInfo.GetFileSystemInfos()等效的方法,因此需要进行一些修改.

I'll give that a try, though I note immediately it doesn't provide an equivalent method to DirectoryInfo.GetFileSystemInfos() so it's going to need some modification.

这篇关于有什么方法可以解决FileSystemInfo.Fullname有时抛出的PathTooLongException的问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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