search files by keyword/wildcard in csharp

Dear experts,

I would like to write just a really small console application which searches for files (like when you search in windows explorer) by keyword. Can I somehow use the built in search capabilities in Windows? Because I already found a code to do file search, but that code only search that particular directory WITHOUT subdirectories :(
I would need two output: the name of the file and the path of the file. Just these two.

Thank you a lot for your help,
Chris
LVL 5
mkriszAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
x77Connect With a Mentor Commented:
Create your own Function to Recursive Find files

            List<string> Result = new List<string>(100);
            RecursiveFind(@"c:\", @"*.Exe", Result);

public void RecursiveFind(String Path, String Mask, List <string> Result)
        {
            try
            {
                foreach (string f in System.IO.Directory.GetFiles(Path, Mask)) Result.Add(f);
            }
            catch { }

            foreach (string d in System.IO.Directory.GetDirectories(Path))
                RecursiveFind(d, Mask, Result);
        }

Open in new window

0
 
x77Commented:
To get DirectoryPath / FileName:

            foreach (string f in Result)
            {
                string PathName = System.IO.Path.GetDirectoryName(f);
                string FileName = System.IO.Path.GetFileName(f);
            }

0
 
lenordisteConnect With a Mentor Commented:
here is a nice article from MSDN explaining how to do file searches in LINQ:
http://msdn.microsoft.com/en-us/library/bb546159.aspx

also, here are some more file search futures you can work on: http://msdn.microsoft.com/en-us/library/bb397911.aspx

I use something similar to the top link in production and it works like a charm !
0
 
lenordisteCommented:
I meant "features" not "futures"... :)
0
 
mkriszAuthor Commented:
ok.
0
All Courses

From novice to tech pro — start learning today.