RE: [PHP] Reading Directories
| From: | Christensen, BruceX R | Date: | Mon, 07 Aug 2000 20:01:06 +0000 |
| Subject: | RE: [PHP] Reading Directories | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-10528@lists.php.net to get a copy of this message | ||
Just use either a string function or a regex to check if the last char is a
/ (note the ereg below):
<?php
$d = dir("some_dir/");
while($entry=$d->read())
{
if ($entry != "." && $entry != ".." && ereg("/$",
$entry))
{
echo "<A HREF=\"track_list.php3\">$entry</A><BR>\n";
}
}
$d->close();
?>
--Bruce
Bruce Christensen
Intel Corporation
brucex.r.christensen@intel.com
-----Original Message-----
From: Phillip S. Baker [mailto:phillip@wordsandimages.com]
Sent: Monday, August 07, 2000 12:46 PM
To: php-general@lists.php.net
Subject: [PHP] Reading Directories
Greetings All,
I am creating a script that reads the contents of a directory.
However I only want it to read the names of the directories and not
the files that are in a particular directory.
I have this bit of code.
<?php
$d = dir("some_dir/");
while($entry=$d->read())
{
if ($entry != "." && $entry != "..")
{
echo "<A HREF=\"track_list.php3\">$entry</A><BR>\n";
}
}
$d->close();
?>
Now the files that I have in some_dir are listed as.
new_dir/
another_dir/
file.txt
anotherfile.bat
I only want to above script to display
new_dir
another_dir
How do I go about doing that?
--
Phillip S. Baker
phillip@wordsandimages.com
Words & Images, Inc.
1535 Seabright Avenue, Suite 100, Santa Cruz, CA 95062
Direct Line (831) 420-2641 / Fax (831) 458-0808