C# program to demonstrate the use of Exists property

In this article, we will learn how to check a directory is exist or not using Exists property? Here we will use class DirectoryInfo.
Submitted by IncludeHelp, on November 16, 2017


This is a method of "DirectoryInfo" class, it is used to check whether a directory exists on or not.


bool DirectoryInfo.Exists

Return value:

Returns the Boolean value true/false.


using System;
using System.IO;

namespace ConsoleApplication1
    class Program
        static void Main()
            DirectoryInfo d = new DirectoryInfo("mydir");

                Console.WriteLine("Directory exists");
                Console.WriteLine("Directory does not exists");


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.

C#.Net DirectoryInfo Class Programs »


What's New (MCQs)

Comments and Discussions!

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.