Solved

all the files in one folder (and all the files that are in that folder)

Posted on 2013-01-16
2
283 Views
Last Modified: 2013-01-17
<?php

$filesarray = array();
$dirsarray = array();
$folder_location='C:/Users/Acer/Documents/';
if(!is_readable($folder_location))
{
  echo "You don't have enough permissions to access this folder!";
  die();
}

if ($handle = opendir($folder_location)){
    echo "Opened the folder successfully!<br>\n";
    while (false !== ($entry = readdir($handle))) {
        if ($entry != "." && $entry != "..")
        {
            if(is_file($folder_location.''.$entry)) {
                echo "$entry<br />";
                $filesarray[] = $entry;
            }
            elseif(is_dir($folder_location.''.$entry)) {
                echo "$entry<br />";
                $dirsarray[] = $entry;
            }
        }
    }
    closedir($handle);
}
else
{
  echo "There was an error opening the folder!";
  die();
}

echo '<pre>';
print_r($filesarray);
print_r($dirsarray);
echo '</pre>';
foreach($filesarray as $key=>$value){
echo $value.'<br>';
}
foreach($dirsarray as $key=>$value){
echo $value.'<br>';
}
?>

Open in new window




this reads all the folders and files in one windows directory

but how to read all the files that are in all the folders in one windows directory

documents
file1
file2
documents/folder1
file1
file2
file3
documents/folder2
file1
file2
documents/folder3
file1
0
Comment
Question by:rgb192
2 Comments
 
LVL 12

Accepted Solution

by:
sivagnanam chandrakanth earned 500 total points
ID: 38785909
use below function, replace the folder path in $path variable in third line from below

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

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

readDirs($path);

Open in new window

0
 

Author Closing Comment

by:rgb192
ID: 38788291
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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…
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 …

863 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

26 Experts available now in Live!

Get 1:1 Help Now