I have an array of strings to delete:
string[] delStrings = {"aaa", "bbb", "ccc", "ddd"}
Then I have a List of directories:
List<string> dirs = new(Directory.EnumerateDirectories(path));
So far I have:
var matches = from dir in dirs
where delStrings.Any( str => dir.Contains(str) )
select dir;
foreach ( string oldName in matches ) {
// ==> how to delete any delString <==
// something such
// string subString = delStrings.Any( str => oldName.Contains(str) )
string newName = oldName.Replace( subString, string.Empty );
System.IO.Directory.Move( oldName, newName );
}
Which gets all directory names that contain a delString. Now I want to replace any delString in every entry of dirs by string.Empty.
How is this accomplished most efficient?