C# Program to Show the Use of Exists Property
DirectoryInfo class provides different types of methods and properties for creating, moving, deleting, renaming, and modifying directories and subdirectories. Exists property is the property of DirectoryInfo class. This property is used to check whether a directory exists or not and return the boolean value accordingly. It will return true if the directory exists, otherwise, it will return false. It will also return if any error occurs while determining if the file exists, or if the specified file is missing, or if the caller does not get permission to read the specified file.
Syntax:
bool DirectoryInfo.Exists
Example:
C#
// C# program to understande the use of Exists Property using System; using System.IO; class GFG{ static void Main() { // Getting the directory information DirectoryInfo information = new DirectoryInfo( "sravan_directory" ); // Checking whether the given directory // exists or not // Using Exists property if (information.Exists) Console.WriteLine( "Exists" ); else Console.WriteLine( "Not Exists" ); } } |
Output:
Not Exists
Contact Us