Page 1 of 1

directory not being recognized with is_dir() or filetype()

Posted: Sun Oct 08, 2006 11:06 pm
by s.dot

Code: Select all

if($handle = opendir(getcwd().DIRECTORY_SEPARATOR.'themes'))
{
	while(false !== ($file = readdir($handle)))
	{
		echo $file.' - '.filetype($file).'<br />';
	}
}
This is outputting....

Code: Select all

. - dir
.. - dir

Warning: filetype() [function.filetype]: Lstat failed for crap in C:\Apache2\htdocs\test\class\test.class.php on line 36
crap - 

Warning: filetype() [function.filetype]: Lstat failed for default in C:\Apache2\htdocs\test\class\test.class.php on line 36
default -
It seems PHP is not recognizing that 'crap' and 'default' are directories. I thought I needed a full path to this, so I used getcwd().DIRECTORY_SEPARATOR.'themes'. Even using a relative path 'themes/' it still does this.

I am using php 5.1.2, apache 2, on windows.

Posted: Mon Oct 09, 2006 12:01 am
by s.dot
Here is the entire function.. in case that helps.

Code: Select all

//gather available themes
function get_available_themes()
{
	if($handle = @opendir('themes'))
	{
		$themes = array();
		while(false !== ($file = readdir($handle)))
		{
			echo $file;
			if(is_dir($file) && ($file != '.' && $file != '..'))
			{
				$themes[] = $file;
			}
		}
		
		if(empty($themes))
		{
			return false;
		}
	} else
	{
		return false;
	}
	
	return $themes;
}
Since I have the echo in there, it echos that it's finding all the directories...

Code: Select all

.
..
crap
default
If I throw an is_dir() in there... it outputs this

Code: Select all

.
..
It won't recognize my 'crap' and 'default' directories. :cry:

Posted: Mon Oct 09, 2006 4:39 am
by volka
readdir only returns the filename, not including the path given to opendir(), i.e. 'default' not 'themes/default'.

Posted: Mon Oct 09, 2006 5:55 pm
by s.dot
Bah. I have worked with these functions so many times, I felt for sure this was a bug. I even reported it to php.net as a bug with my first bug report ever. I guess everytime i've used them in the past they have in the same directory. Now i feel like a bag of suck. :cry:

Posted: Mon Oct 09, 2006 6:15 pm
by volka
you might also be interested in
http://de2.php.net/glob wrote:array glob ( string pattern [, int flags] )
[...]
Returns an array containing the matched files/directories, an empty array if no file matched or FALSE on error.
[...]
GLOB_ONLYDIR - Return only directory entries which match the pattern