reading folders and files
Posted: Fri Feb 07, 2003 3:24 am
Does anybody have a function/class that can read through a folder/file structure and "snif" every file it finds 
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
$files = getAllFiles("."); // dir goes here
while (list ($key, $val) = each ($files))
echo "$val<BR>\n";
function getAllFiles ($dir) {
$files = array();
$single_files = array();
$d = opendir ("$dir");
//list the files in the dir
while ($file = readdir ($d)) {
if ($file == ".." || $file == ".") continue;
if (is_dir ($dir."/".$file)) {
$dirFiles = getAllFiles($dir."/".$file);
foreach ($dirFiles as $f)
$filesї] = $file."/".$f;
} else {
$single_filesї] = $file;
}
}
closedir ($d);
sort($files);
sort($single_files);
return array_merge($single_files,$files);
}