Guest User

Test

a guest
Feb 12th, 2012
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.78 KB | None | 0 0
  1. import java.io.File;
  2. import java.util.ArrayList;
  3. import java.util.Arrays;
  4.  
  5. class DirList {
  6.  
  7.     public static void main(String[] args) {
  8.         int depth = 2;
  9.         String rootPath = "C:\\";
  10.  
  11.         String list[] = new File(rootPath).list();
  12.  
  13.         File f = null;
  14.         for (int i = 0; i < list.length; i++) {
  15.             f = new File(rootPath + list[i]);
  16.  
  17.         if(depth > 0)
  18.             if (f.isDirectory()) {
  19.         for (File file2 : f.listFiles()) {
  20.                     System.out.println(file2.toString());
  21.                    
  22.                System.out.println(f.getName() + " is DIRECTORY");
  23.                 }
  24.             } else if (f.isFile()) {
  25.                 System.out.println(f.getName() + " is FILE");
  26.             }
  27.  
  28.         }
  29.  
  30.     }
  31.  
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment