Hi,
How do I find all folders from a folder? I will need that for a theme support.
Thanks!
How to find all folders from a folder?
Moderator: General Moderators
- kaisellgren
- DevNet Resident
- Posts: 1675
- Joined: Sat Jan 07, 2006 5:52 am
- Location: Lahti, Finland.
- jayshields
- DevNet Resident
- Posts: 1912
- Joined: Mon Aug 22, 2005 12:11 pm
- Location: Leeds/Manchester, England
Straight from the manual with one extra condition added to the second if statement.
Code: Select all
<?php
if ($handle = opendir('.')) { //Leave it as '.' for current dir, or change to dir you want to look in
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." && is_dir($file)) {
echo "$file\n";
}
}
closedir($handle);
}
?>Code: Select all
<?php
print_r(glob('*', GLOB_ONLYDIR));
?>- kaisellgren
- DevNet Resident
- Posts: 1675
- Joined: Sat Jan 07, 2006 5:52 am
- Location: Lahti, Finland.
That's good but it will also give me files... I just want to get the folders...jayshields wrote:Straight from the manual with one extra condition added to the second if statement.Code: Select all
<?php if ($handle = opendir('.')) { //Leave it as '.' for current dir, or change to dir you want to look in while (false !== ($file = readdir($handle))) { if ($file != "." && $file != ".." && is_dir($file)) { echo "$file\n"; } } closedir($handle); } ?>