title: c# finding files with some extension on hard disk
body: <p>I want to find all files in whole harddrive  (.jpg, .png, .apk and a few other formats) but this code is not working..all it does is : for example if in my 'D:\' drive I have: 1)a image file 'i1', 2)a folder 'f1' which has image file and 3) another folder 'f2' which has image file and 'f2' contains folder 'f3' which has image file .It only performs 'calcFile()' on contents inside f1 and f2 but not on contents of f3 and i1 same happens with all other partitions .What is wrong here? Any help is appreciated. 
  I hope you understand what is happening because that's the easiest way I could explain my situation, if more info is required just tell me. thanks :)</p>
  
  <pre><code>public void calcDirectory(string token)
      {
  var validExtensions = new[]
          {
  
               ".jpg", ".png", ".apk"
  
          };
          foreach (string s in Directory.GetLogicalDrives())
          {
              DriveInfo driveInfo = new DriveInfo(s);
              if (driveInfo.IsReady)
              {
  
  
                  foreach (string d in Directory.GetDirectories(s))
                  {
                      FileAttributes attrs1 = File.GetAttributes(d);
                      if (!attrs1.HasFlag(FileAttributes.ReparsePoint))
                      {
                          if (!attrs1.HasFlag(FileAttributes.System))
                          { 
                      string[] allFilesInDir = Directory.GetFiles(d);
                      for (int i = 0; i &lt; allFilesInDir.Length; i++)
                      {
                          string file = allFilesInDir[i];
                          string extension = Path.GetExtension(file);
                          if (validExtensions.Contains(extension))
                          {
                              string p = Path.GetFullPath(file);
                              FileAttributes attrs = File.GetAttributes(p);
                              if (attrs.HasFlag(FileAttributes.ReadOnly))
                              {
                                  File.SetAttributes(p, attrs &amp; ~FileAttributes.ReadOnly);
                                  calcFile(file, token);
                              }
                              else
                              {
                                  calcFile(file, token);
                              }
                          }
                      }
  
                  }
              }
             }
           }
          }
      }
  </code></pre>
  
  <p>and I call the calcDirectory() here</p>
  
  <pre><code>public void start()
      {
           string token = File.ReadAllText(tokencalcalculated);
           calcDirectory(token); 
      }
  </code></pre>