EToS
{ ADMIN }
posts: 13
last: 24-Sep-2008
TITLE: Delete files from a folder for a given filename extension
DESCRIPTION: Delete files from folder path that have a specified filename extension
Submitted: 31-Dec-2007 23:07:52 ( 1yrs 1w 0d 9h ago ) Language: C# (*.cs)
Views: 285 Lines of Code: 15 LINES
Rating:
rate: star1
star2
star3
star4
star5
dstar1
dstar2
dstar3
dstar4
dstar5  ( rated! )
  { 0.00 / 5 }
Difficulty: Beginner
Bookmark
//Delete files from specified path that have the specified extensions

private void delete_ext(string path, string ext)
{
	string[] fileNames = System.IO.Directory.GetFiles(path);

	foreach ( string strFiles in fileNames )
	{
		System.IO.FileInfo info = new System.IO.FileInfo(strFiles);
			if (info.Extension.ToLower() == ext.ToLower())
		{
			System.IO.File.Delete(info.ToString());
		}
	}
}