title: Searching all files in directories and sub-directories that contain specific string and remove string
body: <p>A number of PHP files have been compromised on my web server. I need to find the ones that have the issue and remove the problem code. It's taking too long to do manually.</p>
  
  <p>The plan was to provide the top level directory and have the console app search all files in that directory (including ones in sub-directories) and remove the line in each file. </p>
  
  <p>My code is below, it works, but it doesn't seem to look through all directories. Files are correctly updated, but files inside of subdirectories are not. I am not sure where I am going wrong. Any assistance would be appreciated. </p>
  
  <pre><code>public static string check_path = string.Empty;
  public static string log_folder = string.Empty;
  public static string extension = string.Empty;
  
  static void Main(string[] args)
  {
      if (args == null || args.Length &lt; 1)
      {
          Console.WriteLine("Invalid Syntax");
          return;
      }
      else
      {
          shakaka(args[0]);
      }
  }
  
  
  public static void shakaka(string check_fol)
  {
      if (Directory.Exists(check_fol))
      {
          string[] folders = Directory.GetDirectories(check_fol);
          foreach (string folder in folders)
          {
              string[] files = Directory.GetFiles(folder);
              foreach (string file in files)
              {
                  extension = Path.GetExtension(file);
                  if (extension == ".php")
                  {
                      var oldLines = System.IO.File.ReadAllLines(file);
                      var newLines = oldLines.Where(line =&gt; !line.Contains("/*457563643*/"));
                      System.IO.File.WriteAllLines(file, newLines);
                      Console.WriteLine("Updated: " + file);
                  }
                  else
                  {
                      Console.WriteLine("Not a PHP File: " + file);
                  }
              }
          }
  
      }
      else
      {
          Console.WriteLine("Directory Doesn't Exist: " + check_fol);
      }
  }
  </code></pre>
  
  <p>}</p>