c# delete all files in a directory

Seeing if someone has a function that takes a directory path as a variable.
Then code deletes all files in that particular directory.  
LVL 16
carsRSTAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
gdupadhyayConnect With a Mentor Commented:
You can do by following any one below:
using System.IO;

string[] filePaths = Directory.GetFiles(@"c:\MyDir\");
foreach (string filePath in filePaths)
  File.Delete(filePath);

or

Array.ForEach(Directory.GetFiles(@"c:\MyDir\"),
             delegate(string path) { File.Delete(path); });

Open in new window

0
 
carsRSTAuthor Commented:
Thanks - I'll give it a try...
0
 
carsRSTAuthor Commented:
Bless your heart.

Thanks!
0
All Courses

From novice to tech pro — start learning today.