c# how to get files name into a specific folder which have a specific patter



I have a folder that contains these files:



Erb3PCustsExport-303_20080318_223505_000.xml
Erb3PCustsExport-303_20080319_063109_000_Empty.xml
Erb3PCustsImport-303_20080319_123456.xml
Erb3PDelCustsExport-303_20080319_062410_000.xml
Erb3PResosExport-303_20080318_223505_000_Empty.xml
Erb3PResosExport-303_20080319_062409_000.xml


I just care about the files that have CustsExport word in their names.


My question:


How to get these files?


What I have tried:


I got the folder name from app settings section in App.Config like this:



string folderPath = ConfigurationManager.AppSettings["xmlFolder"];


Then I got all the file names like this:



foreach (string file in Directory.EnumerateFiles(folderPath, "*.xml"))
{

}


My problem:


In that way, I got all the files. However, I am just interested in files that have CustsExport in their names.


Could you help me please?


Note:


I am working on .NET 4.5


Many thanks


No comments:

Post a Comment