TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 04-13-2009, 12:21 AM   #1 (permalink)
The Acquainted
 
Peuplarchie's Avatar
 
Join Date: May 2008
Location: Québec
Posts: 104
Thanks: 10
Peuplarchie is on a distinguished road
Application Fix recursive function on a directory listing

Good day to you,
Here i'm still working on my list of files pushed to an array.

I'm now working on recursively display the list, when it read the files and it find a directory, it should go through and list the files and folders.. so on..

I know my code is wrong, this is why I come to you, I want to learn.

My code do the thing but only does it once.

My problem : My code don't read recursively, it only go to the 2nd level of foler if any.

How could I improve this ?



PHP Code:

<?php

$directory 
"Art/";
function 
dirList ($directory)
{

    
//create 2 arrays - one for folders and one for files
   
$folders = array();
   
$files = array();

    
// create a handler for the directory
    
$handler opendir($directory);

    
// keep going until all files in directory have been read
while (false !== ($file readdir($handler))) {  

        
// if $file isn't this directory or its parent,
        // add it to the results array
        
if ($file != '.' && $file != '..')
        
        
// If file is directory, mark it in bold.
       
if(is_dir($directory.$file)) { 
        
array_push($folders,$file);
        
        
// Else not styled
        
}else{
        
array_push($files,$file);
        
    }
    }


    
// tidy up: close the handler
    
closedir($handler);

    foreach(
$folders as $folder) {
      echo 
"<strong>".$folder."</strong><br />";
        
echo 
"<div>";
dirList($directory."$folder.");

echo 
"</div><br/><br/>";
    
    
    }

    foreach(
$files as $file) {
      echo 
$file."<br />";
    }
    

}

dirList($directory);

?>
The big picture is a menu of files and folder.
Each folder result should be placed in a div.
If there is a folder create a new div within the other and list the files in....

Thanks !
__________________
That's why we are not alone on earth... let's build !
Peuplarchie is offline  
Reply With Quote
Old 04-13-2009, 03:04 AM   #2 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

For some reason I feel like I went back in time cause I remember you posting the exact same thing decades ago. :P
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to create a gallery class Tanax Advanced PHP Programming 25 02-19-2013 04:25 AM
Timezone Class: Dealing with Timezones the Proper Way Wildhoney General 2 01-10-2011 11:01 PM
Part 2: Giving our Currency Conversion Script some Responsibility Wildhoney General 15 03-17-2009 01:53 PM
[Tutorial] How to organize your classes | Part 1 Tanax Advanced PHP Programming 10 03-01-2009 10:08 PM
Read Directory Function CHASE Script Giveaway 15 03-12-2008 04:08 PM


All times are GMT. The time now is 04:53 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design