Solved

I want there to be a way to tell which dir the file is in similar to a tree

Posted on 2013-01-17
2
291 Views
Last Modified: 2013-01-20
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_27999224.html

there is an array of dirs and array of file

[files] => Array
        (

        )

    [dirs] => Array
     (
     )


I want there to be a way to tell which dir the file is in similar to a tree

<?php
error_reporting(E_ALL);

$myArray = array();

function readDirs($path){
  $dirHandle = opendir($path);
  while($item = readdir($dirHandle)) {
    $newPath = $path."/".$item;
    if(is_dir($newPath) && $item != '.' && $item != '..') {
       echo "Found Folder $newPath<br>";
        $myArray['dirs'][] = $newPath;
       readDirs($newPath);
    }
    else{
      echo '&nbsp;&nbsp;Found File or .-dir '.$item.'<br>';
        $myArray['files'][] = $newPath;
    }
  }
  return $myArray;
}

$path =  ".";
echo "$path<br>";

$myArray = readDirs($path);

echo '<pre>';
print_r($myArray);

Open in new window

0
Comment
Question by:rgb192
2 Comments
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
Comment Utility
There may be a germ of an idea in the SPL:
http://php.net/manual/en/class.recursivedirectoryiterator.php
0
 

Author Closing Comment

by:rgb192
Comment Utility
so I need to learn more about the spl

thank you
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now