Monday, May 30, 2011

How to delete files in a directory

Just write one line code to delete the files from the directory.

string dirPath = "C://XMLFiles";
//search for the xml files in the directory and delete all files
new List(Directory.GetFiles(dirPath,@"*.xml")).ForEach(file => { File.Delete(file); });

Here, I am deleting all the XML files from the dirPath directory.