I need to check a directory to see if there are any files whose file name contains a specific keyword and if there are, to delete them. Is this possible?
For exampl
new List(Directory.GetFiles(@"C:\Folder")).ForEach(file => {
if (file.IndexOf("apple", StringComparison.OrdinalIgnoreCase) >= 0)
File.Delete(file);
});
or
new List(Directory.GetFiles(@"C:\Folder")).ForEach(file => {
Regex re = new Regex("apple", RegexOptions.IgnoreCase);
if (re.IsMatch(file))
File.Delete(file);
});