Reputation: 627
I need to populate 2 lists in my application. The first list should contain only .txt files while the second one should contain .jpg files.
Now what I do is something like:
foreach (string file in fileList)
{
if (file != "__ApplicationSettings")
{
...
}
}
But how can I also check file extension?
Thanks in advance.
Upvotes: 1
Views: 237
Reputation: 133995
Using the Path.GetExtension method:
if (Path.GetExtension(file) != ".jpg")
{
...
}
Upvotes: 2