Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8800263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:32:26+00:00 2026-06-14T00:32:26+00:00

Is there a way to simplify this linq expression, or is there a better

  • 0

Is there a way to simplify this linq expression, or is there a better way of doing this?

Directory.GetFiles(dir, "*.*", SearchOption.AllDirectories)
         .Where(s => s.EndsWith(".jpg", StringComparison.OrdinalIgnoreCase) ||
                     s.EndsWith(".gif", StringComparison.OrdinalIgnoreCase) ||
                     s.EndsWith(".png", StringComparison.OrdinalIgnoreCase) ||
                     ...);

Basically I want to return all files of a certain extension. Unfortunately, this method isn’t very flexible. I’d rather be able to add extensions to a list and have Directory.GetFiles return those extensions. Is that possible?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T00:32:27+00:00Added an answer on June 14, 2026 at 12:32 am

    If you would like to do your filtering in LINQ, you can do it like this:

    var ext = new List<string> { "jpg", "gif", "png" };
    var myFiles = Directory
        .EnumerateFiles(dir, "*.*", SearchOption.AllDirectories)
        .Where(s => ext.Contains(Path.GetExtension(s).TrimStart(".").ToLowerInvariant()));
    

    Now ext contains a list of allowed extensions; you can add or remove items from it as necessary for flexible filtering.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to simplify this method? Perhaps a way to && both
I was wondering if there is a way to simplify this down from two
Is there a way to simplify this assignmet in Velocity? #if($errors.contains(Field required.) #set($requiredFieldErrors =
In PHP, is there a way to simplify this even more, without using an
Is there a way to simplify this working code? This code gets for an
echo $xml->SLOT1->Effect; echo $xml->SLOT2->Effect; echo $xml->SLOT3->Effect; Is there a way to simplify this by
just doing my Homeworks and discovered this piece A[j]=A[j-1]; j--; is there a way
Is there a way that I can simplify this code: var topic_html = obj.$form.find(#select-topic).html();
Is there any way to simplify this code? Or any way to create another
Can someone help me simplify this code? Is there a way I can permanently

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.