Get All Files in Directory and All Child Directories

Discussion in 'PHP' started by !Unreal, May 6, 2009.

  1. #1
    I need something to read all files in a directory and all files in child directories and any directories below this.

    Could someone provide a snippet for me.

    Thanks :)
     
    !Unreal, May 6, 2009 IP
  2. buldozerceto

    buldozerceto Active Member

    Messages:
    1,137
    Likes Received:
    43
    Best Answers:
    0
    Trophy Points:
    88
    #2
    buldozerceto, May 6, 2009 IP
  3. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #3
    
    
    function displayDir($mainFolder)
    {
       $main = glob("$mainFolder/*");
       foreach($main as $folDir)
       {
          if(is_dir($folDir)
          {
             echo "Folder: $folDir ";
             displayDir($folDir);
          } else {
            echo "File: $folDir ";
          }
    }
    
    PHP:
    Untested.

    Peace,
     
    Barti1987, May 6, 2009 IP
  4. articlesdirectory

    articlesdirectory Greenhorn

    Messages:
    57
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    18
    #4
    Please first of all study recursion.
    Then you can understand the code. If you need more help you are requested to send me PM so that i may send you a script that will work in all situations keeping it in wamp server.

    Regards
    Articles Directories
     
    articlesdirectory, Jul 30, 2009 IP