Re: [PHP] is_dir on WIndows
if (is_dir($file) ($file!=.) ($file!=..)) { $users[]=$file; } It's only adding it to the array if all 3 of those are true. and since $file can't be both '.' and '..' at the same time, it's never matching. I'd do something like: if (is_dir($file) || ($file!=.) || ($file!=..)) continue; Mark wrote: 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!=..)) { $users[]=$file; } } What this should do (if I'm not a complete idiot), is put all the true subdirectories (excluding . and ..) into the array $users. There are two additional subdirectories under the $maildir directory. However the array is empty. As you can see, I tried echoing out $file and whether it is a directory, but it came up as not recognizing the directories as such. With the echos above in place, I get the resource handle, and it echos everything you would expect except that is_dir() fails to recognize the directories. It DOES recognize . and .. as directories, for some bizarre reason. And no, I can't switch to linux. Any ideas? Mark = Mark Weinstock [EMAIL PROTECTED] *** You can't demand something as a right unless you are willing to fight to death to defend everyone else's right to the same thing. *** __ Do you Yahoo!? New and Improved Yahoo! Mail - 100MB free storage! http://promotions.yahoo.com/new_mail -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] is_dir on WIndows
Chris wrote: if (is_dir($file) ($file!=.) ($file!=..)) { $users[]=$file; } It's only adding it to the array if all 3 of those are true. and since $file can't be both '.' and '..' at the same time, it's never matching. I'd do something like: if (is_dir($file) || ($file!=.) || ($file!=..)) continue; That will match everything and anything, files and dot directories... The first statement by the OP should work fine. All three will eval to true if it is a directory, and the directory isn't . or .. -- John C. Nichel ÜberGeek KegWorks.com 716.856.9675 [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] is_dir on WIndows
On Tuesday 28 September 2004 03:54, Mark wrote: With the echos above in place, I get the resource handle, and it echos everything you would expect except that is_dir() fails to recognize the directories. Because is_dir() expects a path to the file as well, otherwise it would be trying to look at $file in it's current working directory (cwd) wherever that may be (most likely not $maildir). It DOES recognize . and .. as directories, for some bizarre reason. Because all directories contain '.' and '..' and hence the cwd of is_dir() would have those. (BTW '.' and '..' ARE directories). -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* QOTD: I looked out my window, and saw Kyle Pettys' car upside down, then I thought 'One of us is in real trouble'. -- Davey Allison, on a 150 m.p.h. crash */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] is_dir on WIndows
--- John Nichel [EMAIL PROTECTED] wrote: Chris wrote: if (is_dir($file) ($file!=.) ($file!=..)) { $users[]=$file; } It's only adding it to the array if all 3 of those are true. and since $file can't be both '.' and '..' at the same time, it's never matching. I'd do something like: if (is_dir($file) || ($file!=.) || ($file!=..)) continue; That will match everything and anything, files and dot directories... The first statement by the OP should work fine. All three will eval to true if it is a directory, and the directory isn't . or .. Which is the problem I'm having. It's not evaluating anything as a directory, except . and .. = Mark Weinstock [EMAIL PROTECTED] *** You can't demand something as a right unless you are willing to fight to death to defend everyone else's right to the same thing. *** __ Do you Yahoo!? Yahoo! Mail Address AutoComplete - You start. We finish. http://promotions.yahoo.com/new_mail -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] is_dir on WIndows
--- Jason Wong [EMAIL PROTECTED] wrote: On Tuesday 28 September 2004 03:54, Mark wrote: With the echos above in place, I get the resource handle, and it echos everything you would expect except that is_dir() fails to recognize the directories. Because is_dir() expects a path to the file as well, otherwise it would be trying to look at $file in it's current working directory (cwd) wherever that may be (most likely not $maildir). It DOES recognize . and .. as directories, for some bizarre reason. Because all directories contain '.' and '..' and hence the cwd of is_dir() would have those. (BTW '.' and '..' ARE directories). Perhaps I should have been more precise (I'm sure I should have...) When I echo $file, it echos what I would expect (the names of the files and directories. I guess I need to prefix $file in the is_dir statement with the full path to the file? So like this? $maildir=MERCURY./MAIL; $handle=opendir($maildir); while ($file = readdir($handle)) { if (is_dir($maildir/$file) ($file!=.) ($file!=..)) { $users[]=$file; } } It seems contrary to what's in the help, but I'll try it out. Thanks! Mark = Mark Weinstock [EMAIL PROTECTED] *** You can't demand something as a right unless you are willing to fight to death to defend everyone else's right to the same thing. *** __ Do you Yahoo!? Yahoo! Mail Address AutoComplete - You start. We finish. http://promotions.yahoo.com/new_mail -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] is_dir on WIndows
Mark wrote: --- John Nichel [EMAIL PROTECTED] wrote: Chris wrote: if (is_dir($file) ($file!=.) ($file!=..)) { $users[]=$file; } It's only adding it to the array if all 3 of those are true. and since $file can't be both '.' and '..' at the same time, it's never matching. I'd do something like: if (is_dir($file) || ($file!=.) || ($file!=..)) continue; That will match everything and anything, files and dot directories... The first statement by the OP should work fine. All three will eval to true if it is a directory, and the directory isn't . or .. Which is the problem I'm having. It's not evaluating anything as a directory, except . and .. Are you giving is_dir() the full path from root to the directory? -- John C. Nichel ÜberGeek KegWorks.com 716.856.9675 [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] is_dir on WIndows
--- Jason Wong [EMAIL PROTECTED] wrote: On Tuesday 28 September 2004 03:54, Mark wrote: With the echos above in place, I get the resource handle, and it echos everything you would expect except that is_dir() fails to recognize the directories. Because is_dir() expects a path to the file as well, otherwise it would be trying to look at $file in it's current working directory (cwd) wherever that may be (most likely not $maildir). It DOES recognize . and .. as directories, for some bizarre reason. Because all directories contain '.' and '..' and hence the cwd of is_dir() would have those. (BTW '.' and '..' ARE directories). Thanks. That worked. Now that I think about it, it makse sense. I should have thought about it first... = Mark Weinstock [EMAIL PROTECTED] *** You can't demand something as a right unless you are willing to fight to death to defend everyone else's right to the same thing. *** ___ Do you Yahoo!? Declare Yourself - Register online to vote today! http://vote.yahoo.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] is_dir on WIndows
* 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. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] is_dir on WIndows
John Nichel wrote: Chris wrote: if (is_dir($file) || ($file!=.) || ($file!=..)) continue; That will match everything and anything, files and dot directories... The first statement by the OP should work fine. All three will eval to true if it is a directory, and the directory isn't . or .. Heh, you're right. I knew I didn't spend enough time on that answer... What I * should* have said was something like: while($file = readdir($handle)) { if ('.' == $file || '..' == $file) continue; if(is_dir($handle.'\\'.$file)) $users[] = $file; } That will work, but it appears you've already sorted the issue out, despite my help. Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php