title: Directory Traversal With Extension in java
body: <p>I'm trying to make a program that Traverses a directory and subdirectories with the specified extension.Here is the code I have so far.I am trying to use endsWith method but because i m passing parameters of file type for recursive calling,i cant use String in the enhanced For Loop.</p>
  
  <pre><code>import java.io.File;
  </code></pre>
  
  <p>public class Traverse_Recursively {</p>
  
  <pre><code>/**
   * @param args
   */
  public static void main(String[] args) {
      File inputFolder = new File("c:/inputFolder");
      traverse(inputFolder, "");
  }
  
  public static void traverse(File parentNode, String leftIndent) {
      if (parentNode.isDirectory()) {
          System.out.println(leftIndent + parentNode.getName());
  
          leftIndent += "     ";
  
          File childNodes[] = parentNode.listFiles();
          for (File childNode : childNodes) {
              traverse(childNode, leftIndent);
          }
      } else {
  
          System.out.println(leftIndent +"|   --&gt; "+ parentNode.getName());
  
      }
  }
  </code></pre>
  
  <p>}</p>