Hi
Check this
1 -
using
cmd.exe
Without looping
private void button1_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("CMD.exe","/c del e:\\test\\*.txt");
}
2-
using Recursive
private void button1_Click(object sender, EventArgs e)
{
DeleteT();
}
void DeleteT()
{
DirectoryInfo di = new DirectoryInfo(@"D:\newww\New Folder\");
FileInfo[] files = (di.GetFiles("*.txt")
.Where(p => p.Extension == ".txt")).ToArray();
int xxx = files.ToList().Count;
if (xxx !=0)
{
files.FirstOrDefault().Delete();
DeleteT();
}
}
Best Regards
M.Mitwalli