  | Mailing List | | Home | | Forum Home | | JBoss - Java Application Server | | Tomcat - JSP/Servlet container | | Struts - A MVC web framework | | iText - An open source PDF Java Library | | JDOM - JDOM XML Parser | | JSP - A mailing list about Java Server Pages specification and reference | | J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition | | J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog | | Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology | |
Struts & Hibernate
|
|
|
  | | | Finding Out Directories on current File System! | Finding Out Directories on current File System! 2005-04-06 - By Ben Hill
Back > How can one find out all directories on a current file system using > java code.
Use the File methods; "list()" to get a listing "isDirectory()" to recursively check through your filesystem starting at the root of the drive you wish to check.
import java.io.File; import java.util.ArrayList;
public class DirLister { private static ArrayList dirs = new ArrayList();
public static void listDirs(File dir) { String[] list = dir.list();
for (int i=0; i<list.length; i++) { File f = new File(dir, list[i]);
if ((f.canRead()) && f.isDirectory()) { dirs.add(f.getAbsolutePath()); listDirs(f); } } }
public static void main(String[] args) { File dir = new File("c:" + File.separator); // or whatever listDirs(dir);
// do something with "dirs" } }
You should have been able to Google for a solution exactly like this.
> needed the same urgently while am myself out info about the same.
No idea what you mean.
HTH
Ben
=========================================================================== To unsubscribe, send email to listserv@(protected) and include in the body of the message "signoff J2EE-INTEREST". For general help, send email to listserv@(protected) and include in the body of the message "help".
|
|
 |