CLEAN Dropdown list of directories

Hi,

I was wondering if anyone could help me out. I am simply trying to create a dropdown list of other directories. Using:
[php]
//SIMPLY as a precurser test, and I UNDERSTAND that this scans directories AND files both, & simply echoes back
$DirList = scandir(’…/ParentDir’);
print_r ($DirList);
[/php]
…I get the following:
Array ( [0] => . [1] => … [2] => .DS_Store [3] => Gallery01 [4] => Gallery02 [5] => Gallery03 [6] => Test_1 )
But, what I eventually want is simply: Gallery01 =>Gallery02 => Gallery03 (without the annoying Mac file, and the “.”, “…” files.
To test my “filter”, I tried:
[php]
$DirList = scandir(’…/path/GalleryImages/’);//this is actually a dir of image dirs
foreach ($DirList as $subdir) {
if(is_dir($subdir)) {
echo “$subdir
”;
}
}
[/php]
The results were echoed as:
“.”
“…”

I filtered out something. But, the target image directories were missing.

If I could figure out how to properly filter out something that doesn’t typically have a suffix (.jpg,tiff, etc…since I’m dealing with directories), I think I know how to build a dropdown menu with the proper results. Can anybody help? Thanks in advance.

Figured it out!..I think. Thanks fir nuthin’ - haha!

So there’s a pathinfo() function that will return the contents in an array

[ul][li]dirname[/li]
[li]basename - If it’s a folder (name and extenstion) or just dirname again[/li]
[li]exension - (filename extension if file)[/li][/ul]

SO, although this isn’t my end product, here’s what I’ve come up with, to produce clean directory results
[php]

<?php function buildDirList($ParentDir) { //to be extracted as an include soon if($contents = @ scandir($ParentDir)) { //to avoid ugly errors $found = array(); foreach ($contents as $item) { //here's the call for the php pathinfo() function $DirInfo = pathinfo($item); //if it has a dirname and no extension, do this: if(array_key_exists('dirname',$DirInfo) && !array_key_exists('extension',$DirInfo)) { $found[] = $item; } } if ($found) { natcasesort($found); foreach($found as $dirname) { echo "$dirname
"; //soon to be echoed instead as } } } } [/php] I hope this helps somebody who, like me, only seems to find people looking for the same extension parameters for file extension, and can't find any info on actual directories.
Sponsor our Newsletter | Privacy Policy | Terms of Service