Reputation: 2118
I've got some simple code as such...
try
{
files = root.GetFiles("*.*");
//throws exception filetoolong exception. Skip file and move
}
catch (UnauthorizedAccessException e)
{
throw;
}
The issue is this may throw an exception if the file path is too long...
System.IO.PathTooLongException was unhandled
Message=The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.
Source=mscorlib
Is there any way just to skip files that are long, currently my program just stops, how do I avoid this exception for now?
Upvotes: 3
Views: 445
Reputation: 16934
More information about the limitations on file path length: Naming Files, Paths, and Namespaces (Windows)
There are a few ways you can work around this, but in order to use those workaround methods, you'd have to likely P/Invoke to the very specialized subset of calls that support filepath lengths > MAX_PATH
Upvotes: 0
Reputation: 603
The only way you can avoid the exception is not to try to enumerate a folder with files which exceed the specs given which are based on the MAX_PATH constant or work with no files.
I've not used it but you could try AplhaFS - http://alphafs.codeplex.com/
Upvotes: 1