note 24389 added to ref.dir
| From: | david@php.net | Date: | Thu, 15 Aug 2002 01:27:45 +0000 |
| Subject: | note 24389 added to ref.dir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-35046@lists.php.net to get a copy of this message | ||
array filelist (string directory)
This function will recurse all dirs below the specified directory and return with a list of all the
files, e.g.
$listoffiles = filelist ("/download");
where /download has the following structure:
/download/file.html
/download/somefolder/anotherfile.tar
/download/somefolder/someotherfolder/afileagain.php
will return
$listoffiles = array (
[0] => "file.html",
[1] => "anotherfile.tar",
[2] => "afileagain.php"
)
I hope you will find this useful.
David Leggett
// File listing function
function filelist ($currentdir, $startdir=NULL, $files=array()) {
chdir ($currentdir);
// remember where we started from
if (!$startdir) {
$startdir = $currentdir;
}
$d = opendir (".");
//list the files in the dir
while ($file = readdir ($d)) {
if ($file != ".." && $file != ".") {
if (is_dir ($file)) {
// If $file is a directory take a look inside
$files = filelist (getcwd().'/'.$file, getcwd(), $files);
} else {
// If $ file is not a directory then add it to our output array
$files[] = $file;
}
}
}
closedir ($d);
chdir ($startdir);
return $files;
}
--
http://www.php.net/manual/en/ref.dir.php
http://master.php.net/manage/user-notes.php?action=edit+24389
http://master.php.net/manage/user-notes.php?action=delete+24389
http://master.php.net/manage/user-notes.php?action=reject+24389