5
I would like to know how to delete all files from a directory.
Suppose I need to delete all files from the Test folder in C: test.
5
I would like to know how to delete all files from a directory.
Suppose I need to delete all files from the Test folder in C: test.
6
In accordance with reply in English:
System.IO.DirectoryInfo di = new DirectoryInfo("YourPath");
foreach (FileInfo file in di.GetFiles())
{
file.Delete();
}
foreach (DirectoryInfo dir in di.GetDirectories())
{
dir.Delete(true);
}
or
System.IO.Directory.Delete(@"C:\Temp", true);
or
using System.IO;
using System.Linq;
var directory = Directory.GetParent(TestContext.TestDir);
directory.EnumerateFiles()
.ForEachInEnumerable(f => f.Delete());
directory.EnumerateDirectories()
.ForEachInEnumerable(d => d.Delete(true));
It worked, thank you very much!
Browser other questions tagged c#
You are not signed in. Login or sign up in order to post.
No need to add
[Resolvido]
at the end of the post. Just accept a response that the system already marks its publication as "solved".– Jéf Bueno