Well, the first problem is that you're passing file paths to a method which expects a directory.
path1 = "c:\Client_Test.xlsx";
// path one is not a directory...
var files1 = Directory.GetFiles(path1).Where(f => searchPattern1.IsMatch(f));
That should throw an IOException
since path1
is a file name.
Next, you're overcomplicating things. No regex is required (or warranted).
You have two cases; files which begin with "Client" and end in "_delete", and those which begin with "Client" and do not. "Client" is common to both, so, just grab all files which begin with client, next find those that end in "_delete", and the rest are those which do not end in "_delete".
var allFiles = Directory.GetFiles(path, "Client*.xlsx");
var endInDdelete = allFiles.Where(f => Path.GetExtension(f) == "._delete");
var doNotEndInDelete = allFiles.Except(endInDelete);
EDIT: I just noticed that you erroneously say that the extension is "_delete", when in reality, it's just the end of the file name. So...
var allFiles = Directory.GetFiles(path, "Client*.*");
var endInDdelete = allFiles.Where(f => Path.GetFileNameWithoutExtension(f).EndsWith("_delete");
var doNotEndInDelete = allFiles.Except(endInDelete);