dc

dc

  • NA
  • 663
  • 0

C# exclude files from directory search

Oct 9 2012 11:46 PM
In a C# 2010 application, I am currently using the following to statements to select files for *summ.xls files.
string[] files = Directory.GetFiles(C:\temp\09_20_2012\CUSTOMER1, "*summ.xls",SearchOption.AllDirectories);

string[] files = Directory.GetFiles("C:\\temp", "*summ.xls", SearchOption.AllDirectories);

However now I need to exclude the following kind of files from the next directory search:
1. *summ.xlsx,
2. *report.xlsx,
and
3. invalid*.xlsx. In this case the files start with the word invalid and the rest of the file name can be anything. However these  files are also of type *.xlsx.

Thus for like the statement,
"string[] files = Directory.GetFiles("C:\\temp", "*summ.xls", SearchOption.AllDirectories);",
can you tell me how I  would  change the statement above to exclude the specific
file names I just listed above?
  Can you show me how to make this coding change and/or point me to a reference I can use to solve the problem?

Answers (1)