DeleteFiles

using System.IO;

public static class MyExtensions
{
	public static void DeleteFiles(this string folderPath, string ext)
	{
		string mask = "*." + ext;

		try
		{
			string[] fileList = Directory.GetFiles(folderPath, mask);

			foreach (string file in fileList)
			{
				FileInfo fileInfo = new FileInfo(file);
				fileInfo.Delete();
			}
		}
		catch (Exception ex)
		{
			//Console.WriteLine("Error Deleting file. Reason: {0}", ex.Message);
		}
	}
}
Example:
string path = @"C:\Temp\test\Sharp";
path.DeleteFiles("cs"); // Deletes all files with a CS extension

Description

Delete all files found on the specified folder with a given file extension.

Details

Double click on the code to select all.

 

;