Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-17-2012, 10:18 PM   PM User | #1
HDRebel88
Regular Coder

 
Join Date: May 2011
Posts: 112
Thanks: 11
Thanked 5 Times in 5 Posts
HDRebel88 is an unknown quantity at this point
Getting subfolders within another folder

I'm trying to get every single sub-folder (and only folders, not files), that is contained within another folder.


Right now the following is outputting: stillsstillstills
It should be outputting: story_board
PHP Code:
function ListFolders($path){
$dir_handle=opendir($path) or die("Unable to open $path");
$dirname end(explode("/"$path));
$dirnames=array();
    while(
false!==($file=readdir($dir_handle))){
        if (
$entry!="." && $entry!="..") {
        
$dirnames[]=$dirname;
        }
    }
closedir($dir_handle); 
return 
$dirnames;

PHP Code:
$folders=ListFolders("./media/stills");
foreach(
$folders as $folder){
$content2.=$folder;


Last edited by HDRebel88; 12-17-2012 at 11:40 PM..
HDRebel88 is offline   Reply With Quote
Old 12-17-2012, 11:40 PM   PM User | #2
HDRebel88
Regular Coder

 
Join Date: May 2011
Posts: 112
Thanks: 11
Thanked 5 Times in 5 Posts
HDRebel88 is an unknown quantity at this point
PHP Code:
function ListFolders($base){
$dir_array=array();
if (!
is_dir($base)){
    return 
$dir_array;
}
if(
$dh=opendir($base)){
    while ((
$file=readdir($dh))!==false){
        if (
$file!= '.' || $file!= '..'){
            if (
is_dir($base.'/'.$file)) {
            
$dir_array[] = $file;
            }
            else{
            
array_merge($dir_arrayrendertask::ListFolders($base.'/'.$file));
            }
        }
    }
    
closedir($dh);
    
$dir_array=array_slice($dir_array,2);
    return 
$dir_array;
}

Had to use array_slice because it prepended three dots to the array. Which was a single dot array element, then a double dot array element.
HDRebel88 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:59 PM.


Advertisement
Log in to turn off these ads.