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

asked on

all the files in a directory php for windows

php for windows

want to iterate through all the files in a directory

save into an array
foreach file, do something

I want to echo the contents of each file (but not with this question)
Avatar of sivagnanam chandrakanth
sivagnanam chandrakanth
Flag of India image

readdir() is the solution for you...

use readdir() to read the list of files and within while loop do the reading of each file and do whatever your scenario requires

http://php.net/manual/en/function.readdir.php
ASKER CERTIFIED SOLUTION
Avatar of Lukasz Chmielewski
Lukasz Chmielewski
Flag of Poland 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

<?php

$filesarray = array();

if ($handle = opendir('C:/gyb/')) {
    while (false !== ($entry = readdir($handle))) {
        if ($entry != "." && $entry != ".." && is_file($entry)) {
            echo "$entry<br />";
            $filesarray[] = $entry;
        }
    }
    closedir($handle);
}

print_r($filesarray);
?>

Open in new window




no output

I think because it says if
or
becuase I changed line 5 to add my windows directory in error
Avatar of rgb192

ASKER

this answer works in the same directory

thanks