System.IO.DirectoryInfo di = new DirectoryInfo("YourPath");
foreach (FileInfo file in di.GetFiles())
{
file.Delete();
}
foreach (DirectoryInfo dir in di.GetDirectories())
{
dir.Delete(true);
}
Directory.Delete(@"folderPath", true);
new System.IO.DirectoryInfo(@"C:Temp").Delete(true);
//Or
System.IO.Directory.Delete(@"C:Temp", true);
System.IO.Directory.Delete("C:TempTest", True)
/// <summary>
/// Delete all files inside a directory
/// </summary>
/// <param name="filePath">Directory Path</param>
Using System.IO;
public static void DeleteFiles(string filePath)
{
if (!Directory.Exists(filePath))
{
throw new Exception("Directory not exist");
}
string[] existingFiles = Directory.GetFiles(filePath);
if (existingFiles.Length > 0)
{
foreach (var item in existingFiles)
{
File.Delete(item);
}
}
}