?
Solved

How to get all sub-directory and all files name in a given directory?

Posted on 2007-03-27
5
Medium Priority
?
1,898 Views
Last Modified: 2013-12-14
Given a specific directory, How to get all sub-directory and all files name in this  directory?
I am using java, thanks

eric
0
Comment
Question by:ericylr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 11

Expert Comment

by:Manish
ID: 18798424
0
 
LVL 11

Expert Comment

by:Manish
ID: 18798425
0
 
LVL 10

Accepted Solution

by:
Jaax earned 2000 total points
ID: 18798440
import java.io.File;
import java.util.ArrayList;

public class Main {
    private ArrayList searchFolders = new ArrayList();
    private ArrayList searchFiles = new ArrayList();

    public static void main(String[] args) {
        Main main = new Main();
        main.retrieveSearchFolders(new File("D:\\Temp")); //Specify ur directory
    }

    private void retrieveSearchFolders(File dir) {
        // System.out.println("Searching for Directory : " + dir);
        File[] files = dir.listFiles();
        if (files != null && files.length > 0) {
            for (int i = 0; i < files.length; i++) {
                if (files[i].isDirectory()) {
                    System.out.println("Adding Folder : " + files[i]);
                    searchFiles.add(files[i]);
                    retrieveSearchFolders(files[i]);
                } else {
                    System.out.println("Adding File : " + files[i]);
                    searchFolders.add(files[i]);
                }
            }
        }
    }
}
0
 
LVL 11

Expert Comment

by:Manish
ID: 18798546
Oh..No help from my link?
0
 

Author Comment

by:ericylr
ID: 18807981
Karanw, sorry. i do not know how to assign the points to different people
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
Suggested Courses
Course of the Month13 days, 19 hours left to enroll

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question