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
297 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 109

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 38790198
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
ID: 38799835
so I need to learn more about the spl

thank you
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

823 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