Link to home
Start Free TrialLog in
Avatar of rgb192
rgb192Flag for United States of America

asked on

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

<?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
ASKER CERTIFIED SOLUTION
Avatar of sivagnanam chandrakanth
sivagnanam chandrakanth
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rgb192

ASKER