Re: is_dir on WIndows
| From: | Curt Zirzow | Date: | Mon, 27 Sep 2004 21:14:20 +0000 |
| Subject: | Re: is_dir on WIndows | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-198013@lists.php.net to get a copy of this message | ||
* Thus wrote Mark:
> I'm having a problem I haven't encountered before. I'm using PHP
> 4.3.4 (upgrading the 4.3.9, but humor me) on Windows.
>
> I'm using the following code snippet to try to get all the
> subdirectories of a directory into an array.
>
> $maildir=MERCURY."/MAIL";
> $handle=opendir($maildir);
> // echo $handle;
> while ($file = readdir($handle)) {
> // echo $file;
> // echo is_dir($file)."<BR/>";
> if (is_dir($file) && ($file!=".") && ($file!="..")) {
You need to provide the full path to is_dir():
is_dir("$maildir/$file");
Otherwise it will simply look for $file relative to where the
script was called from.
A another way you could do this is:
foreach(glob("$maildir/*", GLOB_ONLYDIR) as $dirname) {
// only use the directory name not the full path.
$users[] = substr($dirname, strrpos($dirname, '/')+1);
}
Curt
--
The above comments may offend you. flame at will.