Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8808353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:36:03+00:00 2026-06-14T02:36:03+00:00

I have a folder (some root folder) in my computer that contains a lot

  • 0

I have a folder (some root folder) in my computer that contains a lot of folders and files. I need to create a String Array that contain all paths (starting from the root folder) of the files (I mean only the leaves = files, not folders). How can I do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T02:36:05+00:00Added an answer on June 14, 2026 at 2:36 am

    Using standard Java SE classes and recursion you could do it this way:

    import java.io.File;
    
    public class Test {
        public static void main(String[] args) {
            File root = new File("D:\\Downloaded"); // path to root folder
            process(root);
        }
    
        private static void process(File path) {
            File[] subs = path.listFiles();
            if (subs != null) {
                for (File f : subs) {
                    if (f.isDirectory()) {
                        process(f);
                    } else {
                        System.out.println(f.getAbsolutePath());
                    }
                }
            }
        }
    }
    

    Note, instead of System.out.println() you’d probably want to put the path to some ArrayList.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a folder which contains few files and some directories which I need
I have a folder full of files and I want to search some string
I have a folder that contains more than 200K images. Some images will follow
I have a folder, which was a git repo. It contains some files and
I have some folder with different files. I want to use something like this:
Can anybody guide me in the right direction... I have some folder strucktures that
I have a helper class in my root AppCode folder that saves me time
I have one folder named test located at www.mydomain.com/abc/files/test. I need to change the
I have some custom files in the root of the Web application, set to
I have a root folder and there are sub folders in it. It is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.