Reputation: 602
Is there any way of validating if a path can be correct in .net or do I need to write something myself?
What I have is a string that is supposed to be a valid path such as:
\\server\shared\folder\file.ext
c:\folder\file.ext
.\folder\file.ext
\folder\file.ext
%appdata%\folder\file.ext
The path does not need to exist on the machine where this is run and the network does not need to be accessible, I'm only interested to see if the path could ever be valid.
Was thinking about splitting the path into filename and path and then using the Path.GetInvalidPathChars() and Path.GetInvalidFileNameChars() arrays to check if the path contains invalid filenames which would at least be a start. But there may be better ideas?
Upvotes: 2
Views: 1570
Reputation: 30883
You can use the following library which is part of NDepend: NDepend.Helpers.FileDirectoryPath It has rich API for processing pathes.
Upvotes: 3
Reputation: 20956
Can't you define a valid set of regular expressions? I think we can define the patterns..
Upvotes: 0