how to delete all files in a directory c#

101

how to delete all files in a directory c# -

System.IO.DirectoryInfo di = new DirectoryInfo("YourPath");

foreach (FileInfo file in di.GetFiles())
{
    file.Delete(); 
}
foreach (DirectoryInfo dir in di.GetDirectories())
{
    dir.Delete(true); 
}

delete all dir content c# -

 new System.IO.DirectoryInfo(@"C:\Temp").Delete(true);

 //Or

 System.IO.Directory.Delete(@"C:\Temp", true);

C# delete folder with all contents -

System.IO.Directory.Delete("C:\TempTest", True)

Comments

Submit
0 Comments