Listing specific file types on directories and subdirectories

Discussion in 'PHP' started by filoaman, Feb 3, 2012.

  1. #1
    Hi friends.
    First of all note that I'm not a programmer, i just use php from time to time to solve problems.
    So please if what i ask is very easy don't shoot me....

    MY GOAL:
    I want a script to create a list of specific file type on a directory (and subdirectories) in my server

    Let's say that the directory structure on the server is something like this:

    ../directory/
    ../directory/SubDir_A1/
    ../directory/SubDir_A2/
    ../directory/SubDir_A3/
    ../directory/SubDir_A3/SubDir_B11/
    ../directory/SubDir_A3/SubDir_B12/
    etc.

    I search the web and i find a script:

    <?php
    
    
    //path to directory to scan.
    $directory = "./*/";
     
    //get all files with a .xxx extension.
    $the_files = glob("" . $directory . "*.xxx");
     
    $files = '';
    // create array
    foreach($the_files as $file){ $files[] = "$file"; }
    
    
    foreach ($files as $value) {
      echo "$value<br>";
    }
    
    
    ?>
    
    Code (markup):

    I upload the script on ../directory/ (my "main" directory), I run it and i get something like this:

    ../directory/file1.xxx
    ../directory/file2.xxx
    ../directory/file3.xxx
    ../directory/file4.xxx
    etc.

    If i change the code to
    //path to directory to scan.
    $directory = "./*/*/";
    
    Code (markup):
    i will get something like this

    ../directory/SubDir_A1/file11.xxx
    ../directory/SubDir_A1/file12.xxx
    ../directory/SubDir_A2/file13.xxx
    ../directory/SubDir_A3/file14.xxx
    etc.

    If i change the code to
    //path to directory to scan.
    $directory = "./*/*/*/";
    
    Code (markup):
    i will get something like this

    ../directory/SubDir_A3/SubDir_B11/file11.xxx
    ../directory/SubDir_A3/SubDir_B11/file12.xxx
    ../directory/SubDir_A3/SubDir_B12/file13.xxx
    ../directory/SubDir_A3/SubDir_B12/file14.xxx
    etc.

    WHAT I'M LOOKING FOR....

    Is there a way to modify the script and after uploading the script to my main directory (../directory/) and run it to get this type of list:

    ../directory/file1.xxx
    ../directory/file2.xxx
    ../directory/file3.xxx
    ../directory/file4.xxx
    ../directory/SubDir_A1/file11.xxx
    ../directory/SubDir_A1/file12.xxx
    ../directory/SubDir_A2/file13.xxx
    ../directory/SubDir_A3/file14.xxx
    ../directory/SubDir_A3/SubDir_B11/file11.xxx
    ../directory/SubDir_A3/SubDir_B11/file12.xxx
    ../directory/SubDir_A3/SubDir_B12/file13.xxx
    ../directory/SubDir_A3/SubDir_B12/file14.xxx
    etc.

    Please Advise
    Thank you.
     
    filoaman, Feb 3, 2012 IP