I have a combo box called comboFileTypes
. Inside that is a drop down list containing:
MP4
MOV
MKV
VOB
And after a button press I have the following code to scan a directory for files:
var files = Directory
.EnumerateFiles(sourceDIR.Text, "*.*", SearchOption.AllDirectories)
.Where(s =>
s.EndsWith(".mp4") ||
s.EndsWith(".mov") ||
s.EndsWith(".vob") ||
s.EndsWith(".MP4") ||
s.EndsWith(".MOV") ||
s.EndsWith(".VOB"));
Which is hardcoded. I want the WHERE
option to be dynamically generated from the combobox instead, so that the user can add another type of file if they need to. (Also case insensitive, if that's possible, otherwise I'll just add both cases)
Any help would be appreciated.
You can get values from ComboBox by
var values = comboFileTypes.Items.Cast<string>()
and use it in like this:
var files = Directory
.EnumerateFiles(sourceDIR.Text, "*.*", SearchOption.AllDirectories)
.Where(s => values.Any(v => s.EndsWith(v, StringComparison.OrdinalIgnorecase));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With