Create a Directory Using C#



To create, move and delete directories in C#, the System.IO.Directory class has methods.

Firstly, import the System.IO namespace.

Now, use the Director.CreateDirectory() method to create a directory in the specified path −

string myDir = @"D:\NEW";
if (!Directory.Exists(myDir)) {
   Directory.CreateDirectory(myDir);
}

In the same way, you can create a sub-directory −

string mysubdir = @"C:\NEW\my\";
Directory.CreateDirectory(mysubdir);
Updated on: 2020-06-21T14:00:14+05:30

385 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements