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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:07:39+00:00 2026-05-27T21:07:39+00:00

Anybody know of a ready-made php class which can read a file-system directory recursively

  • 0

Anybody know of a ready-made php class which can read a file-system directory recursively (including all files and sub-directories) and return an array or object or JSON string or XML of the structure?

I would do this myself but a client just called and is insisting on it being done today. Yay.

  • 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-27T21:07:40+00:00Added an answer on May 27, 2026 at 9:07 pm

    You can make use of the in-build RecursiveDirectoryIterator­Docs class to create your wished outcome. In the following example an hierarchical array is created:

    $dir = '.';
    
    $dirit = new RecursiveDirectoryIterator($dir);
    $it = new RecursiveIteratorIterator($dirit);
    $array = array();
    foreach($it as $file)
    {
        $path = substr($file, strlen($dir)+1);
        $parts = explode(DIRECTORY_SEPARATOR, $path);
        $filename = array_pop($parts);
        $dirname = implode(DIRECTORY_SEPARATOR, $parts);
        $build = &$array;
        foreach($parts as $part)
        {
            if (!isset($build[$part])) $build[$part] = array();
            $build = &$build[$part];
        }
        $build[] = $filename;
        unset($build);
    }
    

    $array will then contain the listing:

    Array
    (
        [0] => .buildpath
        [1] => .project
        [.settings] => Array
            (
                [0] => org.eclipse.php.core.prefs
            )
    
        [array] => Array
            (
                [0] => array-keys.php
                [1] => array-stringkey-explode.php
            )
    )
    

    Using json_encode­Docs can simple turn this into something like:

    json_encode($array);
    
    {"0":".buildpath","1":".project",".settings":["org.eclipse.php.core.prefs"],"array":["array-keys.php","array-stringkey-e
    xplode.php"]}
    

    As I’ve written in a comment above, glob can be useful, too.

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

Sidebar

Related Questions

does anybody know of a secure 'read-once' local file access system? Or how one
Does anybody know a ready-made, reliable way to tell the dimensions (width x height)
Anybody know what the best to use to read a XmlEnumAttribute Option 1: With
Hi anybody know how to select and read client page data using c# and
Anybody know of a way to batch NHibernate queries using NHibernate.Linq like you can
Anybody know how to get all of these in a C# app that leads
Anybody know of an efficient algorithm for moving rectangles in a square which contains
Does anybody know good and production ready serialization library for Erlang? I have tried
Does anybody know why the following code only has effect in FF? $(document).ready(function() {
Does anybody know how I can stop this Plugin after it unscrambles the text?

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.