is_dir does not recognize folders
Posted
by Rakoon
on Stack Overflow
See other posts from Stack Overflow
or by Rakoon
Published on 2010-06-08T14:02:54Z
Indexed on
2010/06/08
14:12 UTC
Read the original article
Hit count: 161
Hi
I am trying to make a function that scans a folder for subfolders and then returns a numeric array with the names of those folders.
This is the code i use for testing. Once i get it to print out the folder names and not just "." and ".." for present and above folder all will be well, and I can finish the function.
<?php
function super_l_getthemes($dir="themes")
{
if ($handle = opendir($dir)) {
echo "Handle: {$handle}\n";
echo "Files:\n";
while (false !== ($file = readdir($handle))) {
echo "{$file}<br>";
}
closedir($handle);
}
?>
The above code works fine, and prints out all the contents of the folder: files, subfolders and the "." and ".."
but if i replace:
while (false !== ($file = readdir($handle))) {
echo "{$file}<br>";
}
with:
while (false !== ($file = readdir($handle))) {
if(file_exists($file) && is_dir($file)){echo "{$file}";}
}
The function only prints "." and ".." , not the two folder names that I'd like it to print.
Any help is appreciated.
© Stack Overflow or respective owner