开发者

Validate a path

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 开发者_StackOverflow社区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?


You can use the following library which is part of NDepend: NDepend.Helpers.FileDirectoryPath It has rich API for processing pathes.


Can't you define a valid set of regular expressions? I think we can define the patterns..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜