Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Check If Directory Exists In C#
WhatsApp
Mahesh Chand
4y
421.1k
0
4
100
Article
The System.IO.Directory class in the .NET Framework class library provides static methods for creating, copying, moving, and deleting directories and subdirectories. Before you can use the Directory class, you must import the System.IO namespace.
using System.IO;
Check if a directory Exists
The Directory.Exists method checks if the specified directory exists on the give computer or not. The Exists method takes a full path of the directory including the drive and returns true if the directory exists, else returns false. The following code snippet checks if a directory exists or not. The below code checks if a directory exists and deletes it if the directory exists.
string
root = @
"C:\Temp"
;
// If directory does not exist, don't even try
if
(Directory.Exists(root))
{
Directory.Delete(root);
}
Download free book that has details and code examples on everything about
Working with Directories in C#
check if folder exists
Directory Exists C#
Directory.Exists
Up Next
Ebook Download
View all
Printing in C# Made Easy
Read by 22.3k people
Download Now!
Learn
View all
Mindcracker
Founded in 2003, Mindcracker is the authority in custom software development and innovation. We put best practices into action. We deliver solutions based on consumer and industry analysis.
Membership not found