note 24389 deleted from ref.dir by nicos
| From: | nicos@php.net | Date: | Fri, 04 Jul 2003 12:28:46 +0000 |
| Subject: | note 24389 deleted from ref.dir by nicos | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-51506@lists.php.net to get a copy of this message | ||
Note Submitter: david DOT leggett AT ntlworld DOT com
----
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;
}