C# 验证远程目录是否存在
我正在使用 Directory.Exists 来查看是否输入的目录是有效目录。这对于所有本地目录以及我有权访问的有效远程目录都适用,但对于我无权访问的远程目录,失效速度很慢。
我怀疑这是因为内置的尝试查找该目录的次数都失败了,因为我无权访问它。
如何更快地确定远程目录无效?
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 directories 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于稍微不同的方法,可能值得尝试 DirectoryInfo,在内部它可能使用与 Directory.Exists() 不同的方法:
但要注意, 构造函数 在某些情况下似乎会抛出异常。
由于这不是静态类,因此它的性能可能更差,但我认为值得尝试。
For a slightly different approach, it may be worth giving DirectoryInfo a try, internally it may use a different approach than Directory.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.