FileDocCategorySizeDatePackage
DirList.javaAPI DocExample1632Sun Mar 28 19:08:16 BST 1999None

DirList

public class DirList extends Object

Fields Summary
File
directory
int
indent
static Vector
seen
Constructors Summary
public DirList(String s)

    this(new File(s), 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.addElement(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)


       
    try {
      for (int i = 0; i < args.length; i++) {
        DirList dl = new DirList(args[i]);
        dl.list();
      }
    }
    catch (IOException e) {
      System.err.println(e);
    }