Results 1 to 2 of 2

Thread: recursive function

  1. #1
    Join Date
    Nov 2005
    Posts
    10

    recursive function

    I'm trying to make a script that goes thru all the subfolders within a directory. Later I'll add a part to insert the folder names into a database. The problem is my function won't go any deeper than 2 levels and I haven't been able to figure it out. Can anyone see the problem with this?

    PHP Code:
    function subfolders($folderIn ''$levelIn 0) {
        
    $folderName $folderIn;
        
    $folderIn .= ($folderIn!='') ? '/' '';
        
    $levelOut $levelIn+1;
        
    $tmp glob($folderIn.'*'GLOB_ONLYDIR);
        foreach(
    $tmp as $key=>$value) {
            
    $dir[] = end(explode('/'$value));
            
    $tab '    ';
            
    $str '';
            for(
    $i=0$i<$levelIn$i++) { $str .= $tab; }
            echo 
    $str.$dir[$key]."\n";
            
    subfolders($dir[$key], $levelOut);
        }
    }

    echo 
    '<pre>'."\n";
    subfolders();
    echo 
    '</pre>'."\n"

  2. #2
    Join Date
    Nov 2005
    Posts
    10
    nevermind... I wasn't giving glob() the full path.

    subfolders($folderIn.$dir[$key], $levelOut);

Similar Threads

  1. correct use of a function?
    By numbenator in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 1
    Last Post: 24 Sep 2005, 09:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •