using System;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main()
{
DirectoryInfo d = new DirectoryInfo("mydir");
if(d.Exists)
Console.WriteLine("Directory exists");
else
Console.WriteLine("Directory does not exists");
}
}
}
Output
Directory exists
In this program, we create an object of DirectoryInfo class and initialize with a directory-name, then check directory exists or not using Exists property of DirectoryInfo class.
Note: In above program, we need to remember, when we use "DirectoryInfo" class, System.IO namespace must be included in the program.
Program
Output
In this program, we create an object of DirectoryInfo class and initialize with a directory-name, then check directory exists or not using Exists property of DirectoryInfo class.
Note: In above program, we need to remember, when we use "DirectoryInfo" class, System.IO namespace must be included in the program.