Re: dir command
| From: | David Robley | Date: | Thu, 17 Aug 2000 01:17:50 +0000 |
| Subject: | Re: dir command | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-12135@lists.php.net to get a copy of this message | ||
On 16 Aug, Shane McBride wrote:
> Here is a code snippet that I got from the php manual (php.net).
>
> I am confused about the "read" part of the command, mainly the "->"
> part.
>
> What does this mean?
> What is the handle? Is it necessary?
>
> I want to list only *.html files. How can I do that?
> What arguments go in the () in the read?
>
> As you can see I am a newbie. I did do a search, but I couldn't find any
> more specifics.
>
> <?
> $d = dir(".");
> echo "Handle: ".$d->handle."<br>\n";
> echo "Path: ".$d->path."<br>\n";
> while($entry=$d->read()) {
> echo $entry."<br>\n";
> }
> $d->close();
> ?>
If you are a bit of a newcomer to programming, you might try the 'old'
approach, rather than the class approach. Try the example using
opendir() and readdir(). The second example in readdir() shows how to
ignore the . and .. directory entries; you can extend that to check for
filenames that have the .html extension.
Alternatively, you can exclude any directory entries by testing the
value returned with is_file() or is_dir (found in the filesystem
functions).
Cheers
--
David Robley | WEBMASTER & Mail List Admin
RESEARCH CENTRE FOR INJURY STUDIES | http://www.nisu.flinders.edu.au/
AusEinet | http://auseinet.flinders.edu.au/
Flinders University, ADELAIDE, SOUTH AUSTRALIA