I think this code can help you

//FileLister v1.0
//this program use to list all files in current directory
//author Yih-Shi Lee
//date:1999/08
//Linux-style copyright

import java.io.*;
import java.util.*;

public class FileLister implements FilenameFilter
{
 private String[] subName; //file's subname
 private Vector fileVector = new Vector(); //store all file names

 //extract all files and directories
  public FileLister() {
    this(null);
  }
  //extract all files which their sub-filename equal subName[]
  public FileLister(String[] subName) {
    this.subName = subName;
    extractor("."); // "." is current path
  }
  //extractor files and directories.
  private void extractor(String currentPath) {
    String[] list; //store file list
    String fullFileName;  //file name includes parentpath and filename
    File file = new File(currentPath);  //start at parenet path

      //System.out.println("currentPath :"+currentPath);
      //list all files and directors and store them
      list = file.list(this);
      if(list!=null) {
        for(int i=0;i<list.length;i++) {
          //System.out.println(list[i]);
          fullFileName = currentPath+File.separator+list[i];
          file = new File(fullFileName);
          //System.out.println("path :"+fullFileName);
          if(file.isDirectory()) {
            //System.out.println(list[i]+" is a directory. "+file.getPath());
            //recursive extractor sub-directory
            extractor(fullFileName);
          }
          else {
            fileVector.add(fullFileName);
          }
        }
      }
  }
  //get all files from Vector
  public Vector getFiles() {
    return fileVector;
  }
  //extract the file with specified sub-filename
  public boolean accept(File dir,String name) {

    if(subName!=null) {
      for(int i=0;i<subName.length;i++) {
        if((new File(dir+File.separator+name)).isDirectory())
           return true;
        else if(name.endsWith(subName[i]))
           return true;
      }
      return false;
    }
    else {
     return true;
    }
  }
  //example
  public static void main(String[] argv) {
    String[] name = new String[2];
    Vector list = new Vector();
    name[0]=".html";
    name[1]=".htm";
    //FileLister file = new FileLister(name);
    //list all files
    FileLister file = new FileLister();

    list = file.getFiles();

    for(int i=0;i<list.size();i++) {
      System.out.println(list.elementAt(i));
    }
  }
}

Xizhen Wang �g�D�G

> hi! all,
>
> I want to know how to get the current directory name in java code? Can
> anyone help me?
>
> Thank you!
>
> Xizhen
>
> ___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to