in ASP, you can use Scripting.FileSystemObject component, for example<%
DIM fso
Set fso = CreateObject("Scripting.FileSystemObject")Function ListFile(f)
   Dim f1, fc, s
   Set fc = f.Files
   For Each f1 in fc
      s = s & f1.name & ","
      s = s & f1.Size & ","
      s = s & f1.Path
      s = s & "<BR>"
   Next
   ListFile = s
End Function
Function ShowFolderList(folderspec)
   Dim f, f1, fc, s
   Set f = fso.GetFolder(folderspec)
   s = ListFile(f)
   Set fc = f.SubFolders
   For Each f1 in fc
      s = s & ShowFolderList(f1.Path)
   Next
   ShowFolderList = s
End FunctionResponse.Write ShowFolderList(Server.MapPath("/testcode"))
%>

解决方案 »

  1.   

    in jsp中<%@ page contentType="text/html;charset=gb2312"%>
    <%@ page import ="java.util.*,java.io.*"%><%
    StringBuffer jspConcent = new StringBuffer() ;
    String sSrcName="c:\\java\\test.txt";
    String sPath = "c:\\java" ;
    File objFile = new File(sPath) ;
    if (!objFile.isDirectory())
    out.print("Java不是目录!") ;
    else{
    String[] aFiles = objFile.list() ;
    if (aFiles!=null){
    for(int i=0;i<aFiles.length;i++)
    out.print("<br>"+aFiles[i]) ;
    }
    File[] objFiles = objFile.listFiles() ;
    if (objFiles!=null){
    for(int i=0;i<objFiles.length;i++)
    if (objFiles[i].isDirectory()){
    out.print("<br>"+objFiles[i].getPath()) ;
    jspConcent.append(objFiles[i].getPath()+"\n") ;
    }else{
        out.print("<br>file=="+objFiles[i].getPath()) ;
    if (objFiles[i].delete())
    out.print("<br>"+objFiles[i].getPath()+"被删除!") ;
    }
    } try
    {
    PrintWriter pw = new PrintWriter(new FileWriter(sSrcName, false), true);
    pw.println(jspConcent.toString());
    }
    catch (Exception e)
    {
    System.out.println("error");
    }
    }
              
    %>