How do I construct my search pattern with multiple wild cards?

Posted on 2014-03-13
Last Modified: 2014-03-13
I'm trying to pull files from a directory into a string array. I need to match the pattern for something like this:

"*." + file extension + "*"

so i can pick up files that match this pattern:

but this isn't working. any suggestions?

string[] sFiles;
sFiles = Directory.GetFiles(myGlobalVars.gsDirectory.ToString(), "*." + sLoopExt + "*");
Question by:mikesExpertExchange
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 35

Expert Comment

by:Dan Craciun
ID: 39927457
Have you tried
sFiles = Directory.GetFiles(myGlobalVars.gsDirectory.ToString() + "*." + sLoopExt + "*");

Open in new window

sFiles = Directory.GetFiles(myGlobalVars.gsDirectory.ToString(), "\*." + sLoopExt + "*");

Open in new window

depending on if gsDirectory includes the final "\" or not

Get files only accepts one parameter, the path, AFAIK.


Author Comment

ID: 39927474
I have and neither seem to work. is there another function that i can use that will except 2 parameters?
LVL 35

Accepted Solution

Dan Craciun earned 500 total points
ID: 39927488
OK, can you output
myGlobalVars.gsDirectory.ToString() + "*." + sLoopExt + "*"
Just to see if the path string is constructed properly.

dir x:\path\*.gl* does work in command prompt, so it should work here too, if the path is correct.

Author Closing Comment

ID: 39927594
Thanks for your help.
LVL 35

Expert Comment

by:Dan Craciun
ID: 39927628
Glad I could help!

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question