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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T04:29:40+00:00 2026-05-15T04:29:40+00:00

I know how to recursively list directory contents. I will be using Snow Leopard’s

  • 0

I know how to recursively list directory contents. I will be using Snow Leopard’s enumeratorAtURL:includingPropertiesForKeys:options:errorHandler: method to do this.

However I want to store my findings into a object hierarchy (of, say, objects of a custom FileOrDirectory class that has isLeaf, children, and count attributes).

I need to pre-load the directory and file structure into such a object hierarchy, in order to do whatever I want with NSTreeController and whatnot. I guess the trickiest thing here is to get the children attribute correct in the object hierarchy.

Any ideas?

  • 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-05-15T04:29:40+00:00Added an answer on May 15, 2026 at 4:29 am

    If I understand your question correctly, you could solve this by writing a recursive function that takes the current node (a file or a folder) and returns an object representing it’s structure.

    This is Java, but maybe it conveys my idea. I have omitted isLeaf and count, as their values can be derived from the children.

    class FileOrFolder
    {
        String name;
        FileOrFolder[] children;
        boolean isFile;
    }
    
    private FileOrFolder traverse(File file)
    {
        FileOrFolder fof = new FileOrFolder();
        fof.name = file.getAbsolutePath();
        if (file.isDirectory())
        {
            String[] children = file.list();
            fof.children = new FileOrFolder[children.length];
            for (int i = 0; i < children.length; i++)
            {
                fof.children[i] = traverse(new File(fof.name + "/" + children[i]));
            }
        }
        fof.isFile = file.isFile();
        return fof;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to download a directory with unknown contents recursively via SSH and have
I want to know how to call Ajax function Recursively. My ajax code is
How i can know the current method stack frame while a recursive call in
Know if it's possible to access the iPhone compass in Safari using JavaScript? I
The following function walks recursively through a list and divide it always by half
I would like to list available directories and text files in specific directories recursively
I have a list of objects, each with a bool ShouldRun() method on them.
I would like to know how to recursively print a File[]. I have made
Does anyone know how send() works with generators when used recursively? I expected the
I have a method that has a reference to a linked list and a

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.