Find phrase within .cs files from a specific folder using C #

2

I would like to know how I can fetch a phrase within .cs files from a specific folder.

You do not need to develop code, just want to know what functions to use and how to use them. I could not find anything on Google.

    
asked by anonymous 17.06.2015 / 21:15

1 answer

3

You can use the DirectoryInfo classes and FileInfo , as follows:

 DirectoryInfo dirInfo = new DirectoryInfo(@"C:\projetos\projeto\src");
 foreach (FileInfo arquivo in dirInfo.GetFiles("*.cs", SearchOption.AllDirectories))
 {
    string codigoCSharp = File.ReadAllText(arquivo.FullName);
    if (codigoCSharp.Contains("Minha Frase"))
        Console.WriteLine("Encontrado");
 }
    
17.06.2015 / 21:49