Contact Us
  
 
 
    SearchSearch   RegisterRegister   Log inLog in 

List and display of directories and sub directories java jsp

List and display of directories and sub directories java jsp

 
Post new topic   Reply to topic     Forum Index -> Java,Struts framework, Velocity, JSF, Hibernate, Servlet, JSP, javaBeans
View previous topic :: View next topic  
Author Message
juniormember



Joined: 28 Jun 2008
Posts: 154

PostPosted: Wed Jul 23, 2008 11:12 am    Post subject: List and display of directories and sub directories java jsp Reply with quote

By this code we can get all file and sub directory and directory in jsp and java.

We have to just put our path in String path, and it will display all file inside the folder. Keep in mind execute only those folder who have less file, otherwise it will take time to fetch all files. This code uses recursive to get file inside in depth.

Code:


<%@ page language="java" import="java.sql.*,java.io.*,java.util.*" errorPage="" %>
<%!
public static List recurseDir(String dir) {
      String result, _result[];

      result = recurseInDirFrom(dir);
      _result = result.split("\\|");
      return Arrays.asList(_result);
}

  private static String recurseInDirFrom(String dirItem) {
    File file;
    String list[], result;

    result = dirItem;

    file = new File(dirItem);
    if (file.isDirectory()) {
      list = file.list();
      for (int i = 0; i < list.length; i++)
        result = result + "|"  + recurseInDirFrom(dirItem + File.separatorChar + list[i]);
      }
    return result;
  }
%>
<%
      String path = "C:\\tomcat6\\webapps\\myApp\\WEB-INF\\classes\\com";
      out.println("recursive Dirs from " + path+"<br>");
     List sd=recurseDir(path);
     for(int i=0;i<sd.size();i++)
     {
        out.println(i+"  "+sd.get(i)+"<br>");
     }
   
%>

Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Java,Struts framework, Velocity, JSF, Hibernate, Servlet, JSP, javaBeans All times are GMT
Page 1 of 1

 
Jump to:  
  Quick Post a Reply Topic
     
  Name (required)  
     
  Email Address (will not be published) (required)  
     
  Subject of topic (required)  
     
   
     
   
     
  Advertisement  
     
 
     


  More Links  
 
JSP Introduction
JSP Setup
Simple JSP Example
JSP Variable
Array Declaration in JSP
JSP Forms and User Input
Form Validation
JSP Cookies
JSP Session Object
Loop, content collection, iterator, conditional check in JSP
JSP Application Object
JSP Include
JSP Response Object
JSP Request Object
JSP Error Handling
JSP File Handling Object
JSP Action Tag
JSP Implicit Objects
JSP Declaration
JSP Directive
JDBC Introduction
JDBC Driver
JDBC Connection
JDBC Prepared/Statement
JDBC ResultSet
JDBC Close Connection object
JDBC Insert
JDBC Display Records
JDBC Update
JDBC Delete
JDBC Sorting
JDBC Query
JDBC Exception
JDBC Add Batch
JDBC Transaction/RollBack