I've managed to use the WinAPI SHGetKnownFolderPath()
method to get the path to the Downloads folder, but when using the following code, I can't get it to delete specific types of files:
string rootFolderPath = KnownFolders.GetPath(KnownFolder.Downloads);
**string filesToDelete = @"*Agreement, CCRPCI, SECCI, Debit*.pdf";**
string[] fileList = System.IO.Directory.GetFiles(rootFolderPath, filesToDelete);
foreach(string file in fileList)
{
System.IO.File.Delete(file);
}
What do I need to add / change in order to reference multiple different file names? I know for a fact the bit I've highlighted in bold is incorrect.
EDITED -
Is there a way to delete files with different file names but the same extension type? As for the reason behind why I need to do this - My automation tests download various different files which get saved into the downloads folder. As the volume of automation tests is high these documents start to take up a lot of storage. Currently I'm going in and manually deleting them. I'm very new to coding guys and to this forum, I know it's a lot to ask but please have patience with me as I'm only trying to learn. (Already had two down votes)