VOOZH about

URL: https://www.geeksforgeeks.org/c-sharp/c-sharp-program-to-check-given-directory-exists-or-not/

⇱ C# Program to Check Given Directory Exists or not - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

C# Program to Check Given Directory Exists or not

Last Updated : 7 Jan, 2022

Given a directory, now our task is to check given directory exists or not. So to this task, we use the Exists() method of the Directory class. This method will return true if the given directory exists, otherwise false. 

Syntax:

public static bool Exists (string? Mypath);

Where, Mypath is a parameter of Exists() method of string type. It represents the location or path of the specified directory. Now the Exists method will return true if the given path refers to the existing directory otherwise it will return false.

Return Type: The return type of this method is a boolean that is either true or false. This method will return true if the given Mypath refers to the existing directory otherwise it will return false.

Example 1:

Output:

The Specified directory Exists

Example 2:

Output:

Not Exist
Comment
Article Tags:

Explore