C# Program to Show the Use of Exists Property
Last Updated :
26 Jan, 2022
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#
using System;
using System.IO;
class GFG{
static void Main()
{
DirectoryInfo information = new DirectoryInfo( "sravan_directory" );
if (information.Exists)
Console.WriteLine( "Exists" );
else
Console.WriteLine( "Not Exists" );
}
}
|
Output:
Not Exists
Share your thoughts in the comments
Please Login to comment...