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

  • Home
  • SEARCH
  • 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 6244115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:16:06+00:00 2026-05-24T12:16:06+00:00

What is the syntax for setting multiple file-extensions as searchPattern on Directory.GetFiles() ? For

  • 0

What is the syntax for setting multiple file-extensions as searchPattern on Directory.GetFiles()? For example filtering out files with .aspx and .ascx extensions.

// TODO: Set the string 'searchPattern' to only get files with
// the extension '.aspx' and '.ascx'.
var filteredFiles = Directory.GetFiles(path, searchPattern);

Update: LINQ is not an option, it has to be a searchPattern passed into GetFiles, as specified in the question.

  • 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-05-24T12:16:07+00:00Added an answer on May 24, 2026 at 12:16 pm

    I believe there is no “out of the box” solution, that’s a limitation of the Directory.GetFiles method.

    It’s fairly easy to write your own method though, here is an example.

    The code could be:

    /// <summary>
    /// Returns file names from given folder that comply to given filters
    /// </summary>
    /// <param name="SourceFolder">Folder with files to retrieve</param>
    /// <param name="Filter">Multiple file filters separated by | character</param>
    /// <param name="searchOption">File.IO.SearchOption, 
    /// could be AllDirectories or TopDirectoryOnly</param>
    /// <returns>Array of FileInfo objects that presents collection of file names that 
    /// meet given filter</returns>
    public string[] getFiles(string SourceFolder, string Filter, 
     System.IO.SearchOption searchOption)
    {
     // ArrayList will hold all file names
    ArrayList alFiles = new ArrayList();
    
     // Create an array of filter string
     string[] MultipleFilters = Filter.Split('|');
    
     // for each filter find mathing file names
     foreach (string FileFilter in MultipleFilters)
     {
      // add found file names to array list
      alFiles.AddRange(Directory.GetFiles(SourceFolder, FileFilter, searchOption));
     }
    
     // returns string array of relevant file names
     return (string[])alFiles.ToArray(typeof(string));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is the syntax for placing constraints on multiple types? The basic example: class
The CSS syntax highlighting in vim is not entirely optimal. For example: div.special_class stops
Could any one tell me the syntax for setting the height and width for
The Sphinx config file hints to it supporting multiple sources for one index, how
JavaScript supports a goto like syntax for breaking out of nested loops. It's not
Possible Duplicate: Declaring Multiple Variables in JavaScript I was setting some variables in jQuery
Does anyone know the syntax for setting a click event or keyup event on
I have DAO code which contains some JDBC with Oracle-specific syntax, for example: select
Setting a page title I have the following MVC View Syntax <title> Category :
I'm setting a cookie on localhost with the following syntax setcookie(testCookie , hello cookie,

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.