Solved

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

Posted on 2013-01-16
2
276 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

744 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

10 Experts available now in Live!

Get 1:1 Help Now