 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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!
Advertisements
 