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 8596843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:46:37+00:00 2026-06-12T00:46:37+00:00

I try to search a file using wild card.My code is: string SearchQuery =”;

  • 0

I try to search a file using wild card.My code is:

          string  SearchQuery ='';
           List<ATTFile> lstFiles = new List<ATTFile>();
            if (Directory.Exists(FilePath))
            {
                DirectoryInfo dirInfo = new DirectoryInfo(FilePath);//File PAth is not a problem.

              foreach (FileInfo file in dirInfo.GetFiles(SearchQuery + "?"))//Want help here  
              {

                    ATTFile obj = new ATTFile();
                    obj.FileName = file.Name;
                    obj.Folder = file.Directory.ToString();
                    obj.Size = int.Parse(file.Length.ToString());
                    obj.Extension = file.Extension;
                    lstFiles.Add(obj);

                }


            }

Code Works if I give full file name.
For Example:
Inside a directory I have following files.

and.jpg
asp.jpg
bb.jpg
cc.jpg 

Using above code if I give full file name its work means SearchQuery ="and.jpg".Its work.But If I give SearchQuery ="a" I want a result

and.jpg
asp.jpg

Starts all files with a.Is it possible using wild card inside GetFiles(SearchQuery + "?").Thanks.

  • 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-12T00:46:38+00:00Added an answer on June 12, 2026 at 12:46 am

    You can use the overload that takes the search pattern:

    String fileNamePart = "a";
    String fileExtension= ".jpg";
    String searchPattern = String.Format("{0}*{1}", fileNamePart, fileExtension);
    dirInfo.GetFiles(searchPattern)
    

    If you want all in one query, you can also use LINQ:

    lstFiles = dirInfo.EnumerateFiles(searchPattern)
                      .Select(file => new ATTFile(){
                          FileName = file.Name;
                          Folder = file.Directory.ToString();
                          Size = int.Parse(file.Length.ToString());
                          Extension = file.Extension;
                      }).ToList();
    

    Note that i’m using DirectoryInfo.EnumerateFiles here since it can be more resource-efficient when you are working with many files and directories.

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

Sidebar

Related Questions

When I try to search a string starting with the slash / character in
I have started to try out to use the new Search API, the demo
Try this code - import java.io.StringReader; public class StringReaderTest { public static void main(String[]
Try this piece of code - public class WhitespaceTest { public static void main(String[]
I want to open any file type by using the code below: System.Diagnostics.Process.Start(pathFile); Is
I am using Python and regex to try and search for text. Given the
I just try to post data to google by using the following code,but always
Need some help for creating a File and String search engine. The program needs
I try searching a file by using awk. How can I ask awk to
Im using the jQuery mobile search filter list: http://jquerymobile.com/test/docs/lists/lists-performance.html Im having somer performance issues,

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.