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 thi
String Path=txtBoxInput.Text+'//'+"RM";
if (Directory.Exists(path))
return true;
using System.IO;
if (Directory.Exists(path))
{
// Do your stuff
}
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.
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
}