how to find a file by its name?

  • Thread starter Thread starter Piz
  • Start date Start date
P

Piz

Hi all.
I have the following problem.
I have to open a directory placed on the server, and get a list of
files that contains a certain string in the file name.
For example:
search string: "myfile.*"

Something like tool "find" of windows.
I found a function "findInFiles" but it doesn't works...don't know why.

Is there any other way? Or i have to build it by myself?

Thanks all
 
The normal method is to loop through the FielInfo classes from the
DirectoryInfo class aimed at the directory in question. You then query each
name for your pattern (Regex?).

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
In addition, I would mention that a recursive function is probably
called-for, to search all sub-directories, sub-directories of
sub-directories, etc. I don't think he needs a Regular Expression for the
type of search he is conducting. The Directory.GetFiles() and
DirectoryInfo.GetFiles() methods can use a search patttern with the "*" and
"?" wildcards.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
A watched clock never boils.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top