1
Answer

C# select file by name

dc

dc

11y
1.2k
1
In a C# 2008 windows application, I want to select all reports that end with
ErrorReport.xlsx.

Here is the code I have so far:

string[] excelFiles = Directory.GetFiles(strFullpath, "*ErrorReport.xlsx")
                                                                     .Select(path => Path.GetFileName(path))
                                                                     .ToArray();
Can you tell me if this code will pick up the excel spreadsheets that end of ErrorReport.xlsx?

This would mean that I do not care about the length of the preceding part of the name. The name could look like the following:
cust1__H98__city_state_ErrorReport.xlsx.

Would this type a name be picked up with the code I have? If not, can you show me code that will pick all the files I am looking for? This could included file names that have special characters in them.

Answers (1)