Validating the existence of a remote directory in C#
I am using Directory.Exists to see if an entered directory is a valid directory. This works well for all local directories, and for valid remote directories that I have access to, but for remote directo开发者_如何学Gories that I don't have access to, it is slow to invalidate.
I suspect that this is because of a built in set number of attempts to find the directory, which are all failing because I don't have access to it.
How can I determine a remote directory is invalid faster?
For a slightly different approach, it may be worth giving DirectoryInfo a try, internally it may use a different approach than Directory.Exists():
DirectoryInfo di = new DirectoryInfo(yourPath);
if(di.Exists())
{
...
}
But watch out, the constructor seems to throw exceptions in some cases. Since this is not a static class, it may perform even worse, but it's worth trying I'd think.
精彩评论