Solved

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

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
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.

829 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