Page 1 of 1

is_dir()...does not recognise directory

Posted: Mon Dec 08, 2003 1:51 pm
by kendall
Hello,

the following is a script that searches an 'images' directory for folders within it

Code: Select all

$dir = dir($path);
	while (false !== ($content = $dir->read())){
		// get files
		if($TYPE == 'files'){
			if($content != "." && $content != ".." && (($ext = strstr($content,$NOT)) != false)){
				if(!is_dir($content)){
					// get file stats
					$date = filemtime($path.'/'.$content);
					$CONTENTS[$date] = $content; 
				}
			}
		}
		if($TYPE == 'folder'){
			if(is_dir($content)){
				echo 'debug folder function GET DIR - content - '.$content.'<br>';
				$date = filemtime($path.'/'.$content);
				$CONTENTS[$date] = $content; 
			}
		}
	}
	$dir->close();
	return $CONTENTS;
My problem is it does not return the directories within the 'images' folder...and they are folders there.

however if i !is_dir() i do get it along with the image files as well.

What is wrong here.

Kendall

Posted: Mon Dec 08, 2003 4:45 pm
by Weirdan
you need to construct the relative path to the file as $dir->read() returns filename only. Do it like you're doing it for filemtime function:

Code: Select all

if(is_dir($path."/".$content))
    //do something

is_dir()...does not recognise directory

Posted: Tue Dec 09, 2003 8:30 am
by kendall
Wierd,

hmmm...is this really what i ought to do?....the thing is if i were to change the path to search for folders within the same "root" it would turn up fine. but i will try your scenario.

Thanks

Kendall