Solved

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

Posted on 2014-03-13
5
316 Views
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:

filename1.gl
filename1.gl1

but this isn't working. any suggestions?

string[] sFiles;
sFiles = Directory.GetFiles(myGlobalVars.gsDirectory.ToString(), "*." + sLoopExt + "*");
0
Comment
Question by:mikesExpertExchange
[X]
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
5 Comments
 
LVL 35

Expert Comment

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

Open in new window

or
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.

HTH,
Dan
0
 
LVL 1

Author Comment

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

Accepted Solution

by:
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.
0
 
LVL 1

Author Closing Comment

by:mikesExpertExchange
ID: 39927594
Thanks for your help.
0
 
LVL 35

Expert Comment

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

Featured Post

Business Impact of IT Communications

What are the business impacts of how well businesses communicate during an IT incident? Targeting, speed, and transparency all matter. Find out more in this infographic.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

739 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