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 8102809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:20:17+00:00 2026-06-05T23:20:17+00:00

i know the basics of recursion but in the given code i m facing

  • 0

i know the basics of recursion but in the given code i m facing difficulty to understand the flow.
please help me guys…

public ArrayList<String> searchFolders(File fo) {

    if (fo.isDirectory()) {

        String internalNames[] = fo.list();



        for (int i = 0; i < internalNames.length; i++) {
            searchFolders(new File(fo.getAbsolutePath() + "\\"+ internalNames[i]));
            path = fo.getAbsolutePath() + "\\" + internalNames[i];
        }
    }
    if (fo.isFile()) {

        alist.add(fo.toString());


    }


    return alist;
}
  • 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-05T23:20:18+00:00Added an answer on June 5, 2026 at 11:20 pm

    Basically, this code is getting all of the contents of a directory and adding them to the global variable alist.

    You give it a directory.
    If it’s a file, then it adds its name to the list and the method returns (files can’t have subfolders).

    If it’s a folder, then it lists all of the things in the folder:

    String internalNames[] = fo.list();
    

    And then executes the same search for each item in the folder:

    searchFolders(new File(fo.getAbsolutePath() + "\\"+ internalNames[i]));

    So, if the item that you are currently searching is a file (if fo.getAbsolutePath() + "\\"+ internalNames[i] is the directory of a file), then it just adds the file to the global ArrayList.

    Otherwise, if it is a folder, it searches it just like it just searched the folder that it just looks at, and lists all of the files in the folder.

    You don’t seem to use the variable path.

    When you return alist, you are returning all of the files that you have found in the folder (and its subfolders) so far.
    You are not returning folder names, since when fo.isDirectory(), you aren’t adding its name to alist.

    enter image description here

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

Sidebar

Related Questions

I know basics of UML and java's OO interpretations using class diagrams. But after
I have a problem with operators. Generally I know basics of using operators. But
I understand the basics of networking such as Lan and stuff. I know what
I want to know about Virtualization in detail. But start from basics, like what
I know the basics of this methods,procedures,function and classes but i always confuse to
I am a beginner but know the basics and am peering into more advanced
I am new to the facebook graph API ,but I know the basics. Now
i know the basics of js the language for several years, but never had
I know the basics of memory management, but not the internals of how iOS
What functionality of BAM can we use in EDI? I know BAM basics, but

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.