is_dir
Posted: Sat May 25, 2002 1:29 pm
I am having trouble understanding howi s_dir() function operates. I am using a while loop to read the content of a directory. In my output I only want to display directories, not files. The following code does not work. It prints the filenames also.
I had to include the directory one level up from the one I am reading to get the is_dir() function to work. This works. It skips files and prints directories.
Can anyone explain why?
Code: Select all
$rootDirName = "Topics"; // set the top level folder
$rootDir = opendir($rootDirName);
// step through each folder (skip files) stored in $rootDir
while ($rootFolder = readdir($rootDir))
{
if (is_dir($rootFolder) ) {
print ...;
}
} // end whileCode: Select all
$rootDirName = "Topics"; // set the top level folder
$rootDir = opendir($rootDirName);
// step through each folder (skip files) stored in $rootDir
while ($rootFolder = readdir($rootDir))
{
$folder = $rootDirName . ""e; . $rootFolder;
if (is_dir($folder) ) {
print ...;
}
} // end whileCode: Select all