在c#中检查路径中是否存在文件夹?
如何检查目录中是否存在名为 RM
的文件夹...我已经通过像 txtBoxInput.Text
这样的文本框给出了目录路径,并且在这个路径中我必须检查。 ..有什么建议吗?
How to check whether a folder named RM
exists inside a directory...I have given the directory path through textbox like txtBoxInput.Text
and in this path i have to check...Any suggestion?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Path.Combine 和 Directory.Exists ?
http://msdn.microsoft.com/en-us /library/system.io.path.combine.aspx
http://msdn.microsoft.com/en-us/library/system.io.directory.exists.aspx
Path.Combine and Directory.Exists ?
http://msdn.microsoft.com/en-us/library/system.io.path.combine.aspx
http://msdn.microsoft.com/en-us/library/system.io.directory.exists.aspx
您可以使用
Directory.Exists()
来测试文件夹在特定时刻是否存在,但请谨慎使用!如果你做了类似的事情:你就陷入了一个典型的错误。在
Directory.Exists()
调用和// Do Something in path
之间,用户完全有可能删除该目录。无论如何,每当进行文件 I/O 时,必须处理在某些内容不可访问、不存在等情况下抛出的异常。无论如何,你都必须处理所有的错误,通常不值得在顶部进行额外的、多余的检查。You can use
Directory.Exists()
to test whether a folder exists at a particular moment in time, but use it with caution! If you do something like:you've fallen into a classic blunder. It's entirely possible that, between the
Directory.Exists()
call and the// Do something in path
, a user will have deleted the directory. No matter what, whenever you do file I/O, you must handle the exceptions that get thrown if something isn't accessible, doesn't exist, etc. And if you have to handle all the errors anyway, it frequently isn't worth the effort to put an additional, superfluous check at the top.String Path=txtBoxInput.Text+'//'+"RM";
String Path=txtBoxInput.Text+'//'+"RM";