C# Program to Check Given Directory Exists or Not

You are currently viewing C# Program to Check Given Directory Exists or Not

C# program to check given directory exists or not

using System;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main()
        {
            bool flag = false;

            flag = Directory.Exists("D:/India");

            if (flag)
                Console.WriteLine("Directory Exists");
            else
                Console.WriteLine("Directory does not exist");

            flag = Directory.Exists("D:/France");

            if (flag)
                Console.WriteLine("Directory Exists");
            else
                Console.WriteLine("Directory does not exist");
        }
    }
}

Output

Directory Exists
Directory does not exist

Ranjith Kumar

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply