FileDocCategorySizeDatePackage
DirList.javaAPI DocExample1460Tue Feb 14 12:55:02 GMT 2006None

DirList

public class DirList extends Object

Fields Summary
private File
directory
private int
indent
private static List
seen
Constructors Summary
public DirList(String name)

    this(new File(name), 2);
  
public DirList(File f)

    this(f, 2);
  
public DirList(File directory, int indent)

    if (directory.isDirectory()) {
      this.directory = new File(directory.getCanonicalPath());
    }
    else {
      throw new IOException(directory.toString() + " is not a directory");
    }
    this.indent = indent;
    String spaces = "";
    for (int i = 0; i < indent-2; i++) spaces += " ";    
    System.out.println(spaces + directory + File.separatorChar);    
  
Methods Summary
public voidlist()

  
    if (!seen.contains(this.directory)) {
      seen.add(this.directory);
      String[] files = directory.list();
      String spaces = "";
      for (int i = 0; i < indent; i++) spaces += " ";    
      for (int i = 0; i < files.length; i++) {
        File f = new File(directory, files[i]);
        if (f.isFile()) {
          System.out.println(spaces + f.getName());
        }
        else { // it's another directory
          DirList dl = new DirList(f, indent + 2);
          dl.list(); 
        }
      }
    }
  
public static voidmain(java.lang.String[] args)


         
      DirList dl = new DirList(args[0]);
      dl.list();