Directory class exposes static methods for creating, moving, and enumerating through directories and subdirectories. This class cannot be inherited.
The following example shows how to check a directory exist, create a directory, then move them to a new directory and delete it
using System;
using System.IO;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
//check directory exist
if (Directory.Exists(@"d:\\csharp"))
{
Directory.CreateDirectory(@"d:\\csharp\\winforms");
}
else
{
//create the directory csharp
Directory.CreateDirectory(@"d:\\csharp");
//create the directory code
Directory.CreateDirectory(@"d:\\csharp\\code");
//move the directory code to foxlearn folder
Directory.Move(@"d:\\csharp\\code", "d:\\foxlearn");
//delete the directory csharp
Directory.Delete(@"d:\\csharp");
}
}
}
}