Given a list of files like this:
file_1.txt
file_2.txt
file_3.txt
file_4.txt
file_5.txt
file_6.txt
How do I invoke Directory.EnumerateFiles()
to get a range or a list of files? For example
Directory.EnumerateFiles(Directory.GetCurrentDirectory(), "file_*.txt", SearchOption.TopDirectoryOnly)
would return all the six files above, and so far so good. But what if I want to get a range (i.e. from file_3.txt
to file_5.txt
) or a list (i.e. file_1.txt
, file_4.txt
and file_6.txt
)?
What I'm looking for is something like this (the code here below doesn't work... it is just to give you an idea):
Directory.EnumerateFiles(Directory.GetCurrentDirectory(), "file_{3-5}.txt", SearchOption.TopDirectoryOnly)
to get a range of files
file_3.txt
file_4.txt
file_5.txt
... and then
Directory.EnumerateFiles(Directory.GetCurrentDirectory(), "file_{1,4,6}.txt", SearchOption.TopDirectoryOnly)
to get an exact list of files
file_1.txt
file_4.txt
file_6.txt
Any help would be appreciated.