在c#中检查路径中是否存在文件夹?

发布于 2024-10-09 02:11:21 字数 119 浏览 0 评论 0原文

如何检查目录中是否存在名为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

反差帅 2024-10-16 02:11:21

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

if (Directory.Exists(Path.Combine(txtBoxInput.Text, "RM"))
{
    // Do Stuff
}

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

if (Directory.Exists(Path.Combine(txtBoxInput.Text, "RM"))
{
    // Do Stuff
}
一曲琵琶半遮面シ 2024-10-16 02:11:21

您可以使用Directory.Exists()来测试文件夹在特定时刻是否存在,但请谨慎使用!如果你做了类似的事情:

if (Directory.Exists(path))
{
    // Uh-oh!  Race condition here!
    // Do something in path
}

你就陷入了一个典型的错误。在 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:

if (Directory.Exists(path))
{
    // Uh-oh!  Race condition here!
    // Do something in path
}

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.

美男兮 2024-10-16 02:11:21
using System.IO;


if (Directory.Exists(path))
{
     // Do your stuff
}
using System.IO;


if (Directory.Exists(path))
{
     // Do your stuff
}
美煞众生 2024-10-16 02:11:21

String Path=txtBoxInput.Text+'//'+"RM";

 if (Directory.Exists(path))
return true;

String Path=txtBoxInput.Text+'//'+"RM";

 if (Directory.Exists(path))
return true;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文