In order to remove a directory or folder using C#, .Net framework provides System.IO namspace which provides Directory.Delete method.
Directory.Delete is a static method that gives you easy way to delete or remove folder or directory. Also we can delete directory or folder using DirectoryInfo class of System.IO namespace.
using System.IO;
class DeleteFolder
{
static void Main()
{
// Delete Directory/folder on C:\ Drive.
Directory.Delete("C:\\TestDirectory");
}
}
class CreateNewFolder
{
static void Main()
{
// Get Directory info or folder info.
DirectoryInfo dir = new DirectoryInfo(@"c:\TestDirectory");
dir.Delete();
}
}
Directory.Delete is a static method that gives you easy way to delete or remove folder or directory. Also we can delete directory or folder using DirectoryInfo class of System.IO namespace.
Examples of deleting directory or folder Directory.CreateDirectory:
Following is sample code for deleting or removing directory or folder on root i.e. at C:/ driveusing System.IO;
class DeleteFolder
{
static void Main()
{
// Delete Directory/folder on C:\ Drive.
Directory.Delete("C:\\TestDirectory");
}
}
Sample code to delete directory using System.IO DirectoryInfo class
using System.IO;class CreateNewFolder
{
static void Main()
{
// Get Directory info or folder info.
DirectoryInfo dir = new DirectoryInfo(@"c:\TestDirectory");
dir.Delete();
}
}