Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2007-03-27
5
Medium Priority
?
1,899 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
Suggested Courses

618 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