1
public List<string> MapMyFiles() { List<FileInfo> batchaddresses = new List<FileInfo>(); foreach (object o in lstViewAddresses.Items) { try { string[] files = Directory.GetFiles(o.ToString(), "*-E.esy"); files.ToList().ForEach(f => batchaddresses.Add(new FileInfo(f))); } catch { if(MessageBox.Show(o.ToString() + " does not exist. Process anyway?", "Continue?", MessageBoxButtons.YesNo) == DialogResult.Yes) { } else { Application.Exit(); } } } return batchaddresses.OrderBy(f => f.CreationTime) .Select(f => f.FullName).ToList(); } 

i would like to add to the array not only

.ESY

but also

"p-.csv"

how do i do this?

5 Answers 5

1

Or just include more filters and select them together:

var filters = new[] { "*-E.esy", "*p-.csv" }; var files = filters.SelectMany(f => Directory.GetFiles(o.ToString(), f)); // .. etc. 
Sign up to request clarification or add additional context in comments.

Comments

0

Assuming that your code works for one set of wildcards...

Then after these lines:

string[] files = Directory.GetFiles(o.ToString(), "*-E.esy"); files.ToList().ForEach(f => batchaddresses.Add(new FileInfo(f))); 

Add these:

files = Directory.GetFiles(o.ToString(), "*p-.csv"); files.ToList().ForEach(f => batchaddresses.Add(new FileInfo(f))); 

Comments

0

I think you have to iterate multiple times with different wildcards.

2 Comments

Create a List<string> and call AddRange() multiple times.
You already are appending, to a List, you just need to do it again with new arguments.
0
public List<string> MapMyFiles() { List<FileInfo> batchaddresses = new List<FileInfo>(); foreach (object o in lstViewAddresses.Items) { DirectoryInfo di = new DirectoryInfo(o); if (!di.Exists && MessageBox.Show(o.ToString() + " does not exist. Process anyway?", "Continue?", MessageBoxButtons.YesNo) != DialogResult.Yes) Application.Exit(); (new List<string>(new[]{ "*-E.esy", "*p-.csv" })).ForEach(filter => { (new List<string>(di.GetFiles(filter))).ForEach(file => { batchaddresses.Add(new FileInfo(file)); }); }); } return batchaddresses.OrderBy(f => f.CreationTime).Select(f => f.FullName).ToList(); } 

There's my bid; added directory check as well.

Comments

0
 try { foreach (string searchPattern in searchPatterns) { string[] files = Directory.GetFiles(o.ToString(), searchPattern); files.ToList().ForEach(f => batchaddresses.Add(new FileInfo(f))); } } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.