title: How To Scan All File in Folder and Subfolder?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/929276/how-to-recursively-list-all-the-files-in-a-directory-in-c">How to recursively list all the files in a directory in C#?</a>  </p>
  </blockquote>
  
  
  
  <p>How to scan all file in Folder and Subfolder?</p>
  
  <p>Here is the code I have:</p>
  
  <pre><code>private void button1_Click(object sender, EventArgs e)
  {
      folderBrowserDialog1.ShowDialog();
      label2.Text = folderBrowserDialog1.SelectedPath;
      viruses = 0;
      progressBar1.Value = 0;
      label1.Text+= viruses.ToString();
      listBox1.Items.Clear();
  }
  
  private void btnScan_Click_1(object sender, EventArgs e)
  {
  
      List&lt;string&gt; search = Directory.GetFiles(folderBrowserDialog1.SelectedPath, "*.*").ToList();
      progressBar1.Maximum = search.Count;
      //foreach (Directory.GetDirectories.search))
  
      foreach(string item in search)
      {
          try
          {
              StreamReader stream = new StreamReader(item);
              string read = stream.ReadToEnd();
              foreach(string st in viruslist)
              {
                  if(Regex.IsMatch(read,st));
                  {
                      viruses+=1;
                      label1.Text+= listBox1.Items.Count;
                      listBox1.Items.Add(item);
                  }
                  progressBar1.Increment(1);
              }
          }
          catch(Exception ex)
          {
          }
      }
  }
  </code></pre>
  
  <p>This code is scaning all files in root folder only, but not in subfolders. How to change this code so it can scan all files in folder and subfolder too? </p>