This example shows you How to use Directory class in C# to Create, Delete, Move and Check exists or not a directory.

The Directory class in c# provides static methods for creating, copying, moving, and deleting directories and sub-directories..etc.

How to create a directory in C# ?

To create a directory in c# you can use the CreateDirectory method of the Directory class.

string path = @"c:\\test";

How to check a directory exist or not in C# ?

To check a directory exist in c# you can use the Exists method of the Directory class. You should check if a folder exist in a directory and create them using the CreateDirectory method.

string path = @"c:\\test";
   //do something

How to move a Directory in C# ?

To move a directory in c# you can use the Move method of the Directory class.

string source = @"c:\\test\\test2";
string target = @"c:\\dotnet";
Directory.Move(source, target);

How to delete a Directory in C# ?

To delete a directory in c# you can use the Delete method of the Directory class.

string path = @"c:\\test";