
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
C# Program to check whether a directory exists or not
Use the Directory. Exists method to check whether a directory exists or not.
Let’s say you need to check whether the following directory exists or not −
C:\Amit
For that, use the Exists() method −
if (Directory.Exists("C:\Amit")) { Console.WriteLine("Directory Amit Exist!"); }
The following is the complete code −
Example
using System.IO; using System; public class Program { public static void Main() { if (Directory.Exists("C:\Amit")) { Console.WriteLine("Directory Amit Exist!"); } else { Console.WriteLine("Directory Amit does not exist!"); } } }
Output
Directory Amit does not exist!
- Related Articles
- Java Program to check whether a file exists or not
- How to check whether a data frame exists or not in R?
- How to use Boto3 to check whether a Glue Job exists or not?
- Golang Program to check a directory is exist or not
- How can I check whether a field exists or not in MongoDB?
- Golang program to check a value exists in the hash collection or not
- C++ Program to Check Whether a Hamiltonian Cycle or Path Exists in a Given Graph
- C++ Program to Check Whether a Number is Prime or Not
- C++ Program to Check Whether a Number is Palindrome or Not
- C# program to check whether a list is empty or not
- Python program to check whether a list is empty or not?
- C Program to Check Whether a Number is Prime or not?
- Java Program to Check Whether a Character is Alphabet or Not
- Java Program to Check Whether a Number is Prime or Not
- Haskell Program to check whether a variable is defined or not

Advertisements