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/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.
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.
Do I really have to do everything with PInvoke
just to be able to read every file on the hard drive?
This looks interesting ... Codeplex Long Path Wrapper
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.
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.