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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T06:29:49+00:00 2026-06-16T06:29:49+00:00

So I want to show whole directory and sub directories. According PHP Doc, The

  • 0

So I want to show whole directory and sub directories.

According PHP Doc,

The RecursiveDirectoryIterator provides an interface for iterating recursively over filesystem directories

Here is my code:

$it = new RecursiveDirectoryIterator("c:\php_win");

foreach ($it as $dir) {
    var_dump($dir->getFilename());
}

Above code only shown one level directory, all sub directories not been shown.

I know I have to use RecursiveIteratorIterator to get all sub directories, but i just do not know why I need to use a RecursiveIteratorIterator iterator.

what is “iterating recursively over filesystem directories” mean? any web links which explains why we need a IteratorIterator?

  • 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-16T06:29:50+00:00Added an answer on June 16, 2026 at 6:29 am

    The RecursiveDirectoryIterator is a class implementing the RecursiveIterator interface.

    The RecursiveIteratorIterator is a class implementing the Iterator interface.

    With a foreach traversal over it, it will take an object implementing RecursiveIterator and do a recursive traversal (tree traversal) on it, here in PHP not only rewinding, fetching current, advancing next and checking validity but also checking if children exists and then internally iterating over these children, too.

    RecursiveIteratorIterator and RecursiveDirectoryIterator diagram

    So the RecursiveIteratorItertor is providing object traversal in linear order while performing a tree traversal over a concrete RecursiveIterator implementaion.

    So the RecursiveDirectoryIterator is only the container. You can iterate over it straight away (e.g. with foreach), but that linear order object iteration would not do the tree traversal.

    That is why the RecursiveIteratorIterator is there, it offers that tree traversal.

    Which is exactly your case: Direct iteration over RecursiveDirectoryIterator only does linear object traversal. Only the RecursiveIteratorIterator knows how to do tree traversal on objects implementing the RecursiveIterator interface. As it implements the Iterator interface itself, it is then possible to do linear object traversal over the tree traversal.

    See as well my answer to How does RecursiveIteratorIterator works in php, it covers the directory iterators exemplary to show the different modes of tree traversal that are possible.

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

Sidebar

Related Questions

I want to show images residing inside a directory in PHP The code which
I want to show whole page in a pop up of size 300*300.Is it
I want to show a div with a loading animation over my page while
I want to show 10- 15 images from a folder in directory but I
i want to show an alertview while other thread(in other thread there is text
I want to show a custom image with some data in it while clicking
I just want to show text please wait while app is searching for satellite
Hi I want to show the number of characeters left for a message while
I use ASP.NET I want to show percentage to user from codebehind while database
My problem is pretty common. I want to show some loading stuff while the

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.