I created files as per
string[] names = {
"Name001.product",
"Name002.product",
"Name003.product",
"Name101.product.prototype",
"Name102.product.prototype",
"Name103.product.prototype",
};
foreach (var name in names)
{
File.WriteAllText(name,"");
}
Then in another event
Directory.GetFiles(
AppDomain.CurrentDomain.BaseDirectory,"*.product")
.ToList()
.ForEach(Console.WriteLine);
Console.WriteLine();
Directory.GetFiles(
AppDomain.CurrentDomain.BaseDirectory,
"*.product.prototype")
.ToList()
.ForEach(Console.WriteLine);
Outputs
C:\Dotnetland\VS2019\ForumQuestion\Demo\bin\Debug\Name001.product
C:\Dotnetland\VS2019\ForumQuestion\Demo\bin\Debug\Name002.product
C:\Dotnetland\VS2019\ForumQuestion\Demo\bin\Debug\Name003.product
C:\Dotnetland\VS2019\ForumQuestion\Demo\bin\Debug\Name101.product.prototype
C:\Dotnetland\VS2019\ForumQuestion\Demo\bin\Debug\Name102.product.prototype
C:\Dotnetland\VS2019\ForumQuestion\Demo\bin\Debug\Name103.product.prototype
I ran the above code with .NET Core 5 and .NET Framework 4.8, both yield the same output.
Another example with a different pattern and predicate.
Directory.GetFiles(
AppDomain.CurrentDomain.BaseDirectory, "Name*.*")
.Where(fileName => !fileName.EndsWith("prototype"))
.ToList()
.ForEach(Console.WriteLine);