title: How to Scan all drives to find specific file extension in Java?
body: <p>I want to scan all disks in my pc to find notepad (.txt) files and copy them into newly created directory. How to do that ? If possible skip some of the folder under C like Windows.Currently I can only scan specific directory. </p>
  
  <p>Thanks</p>
  
  <pre><code>         public void scanFolder(int depth, File file) {
  
      StringBuilder indent = new StringBuilder();
      String name = file.getName();
      String extension;
      String txtcheck = "txt";
  </code></pre>
  
  <p>;</p>
  
  <pre><code>    for (int i = 0; i &lt; depth; i++) {
          indent.append(".");
      }
  
       //Pretty print for directories
      if (file.isDirectory()) {
  
          String seperator = indent.toString() + "|";
          if (isPrintName(name)) {
  
  
          }
      } 
         //Print file name
      else if (isPrintName(name)) {
  
  
          out2 = indent.toString() + file.getName();
          extension = name.substring(name.lastIndexOf(".") + 1, name.length());
          if (txtcheck.equals(extension)) {
  
              outs.add(out2);
  
          }
  
      }
  
      if (file.isDirectory()) {
          File[] files = file.listFiles();
          for (int i = 0; i &lt; files.length; i++) {
              scanFolder(depth + 4, files[i]);
          }
      }
  
  }
  
       scanFolder(0, new File("C:\\lefdef"));
  </code></pre>