Re: Listing the contents of a directory in an array
| From: | Lowell Allen | Date: | Fri, 17 May 2002 12:58:43 +0000 |
| Subject: | Re: Listing the contents of a directory in an array | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-98065@lists.php.net to get a copy of this message | ||
> From: webmaster@tececo.com
>
> I am a newbie so be kind
>
> I have looked into the manual about directory functions etc.
>
> I want to return all the files from a directory into a array.
>
> Could some one give me a few pointers or something?
>
> I keep getting confused but I have used google and the manual.
>
> I can find functions but I am not sure how I can list the files into an array.
$current_dir = "/whatever/";
$dir = opendir($current_dir);
// declare some arrays to put the directory into
$dirs = array();
$files = array();
// move the directory into an array
while ($file = readdir($dir))
{
if ($file == '.' || $file == '..')
{
continue;
}
else
{
if (is_dir($file))
array_push($dirs, $file);
else
array_push($files, $file);
}
}
--
Lowell Allen