reading folders and files
Moderator: General Moderators
reading folders and files
Does anybody have a function/class that can read through a folder/file structure and "snif" every file it finds 
you can do that with opendir/readdir and is_file/is_dir
http://www.php.net/manual/en/function.opendir.php
http://www.php.net/manual/en/function.opendir.php
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);
}