SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2000
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is there a special function that will get all files from a given directory and put them in an array?

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There is no special built in function but here is user-defined function.
    PHP Code:
    <?
        
    function list_files($dir ".") {
            
    $d dir($dir);
            while(
    $file $d->read()) {
                if ((
    $file != ".") && ($file != "..")) {
                    
    $files[] =  $file;
                    }
                else {
                    continue;
                    }    
                }
            
    $d->close();
            return 
    $files;
            }


        
    //Sample Usage takes optional argument 
        //- path to directory to list, defaults to current dir.
        
    $filelist list_files("path/to/list");    
        foreach(
    $filelist as $val) {
            print 
    "$val<br>";
            }

    exit;
    ?>
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    SitePoint Wizard
    Join Date
    Jul 1999
    Location
    Chicago
    Posts
    2,629
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can do this:

    PHP Code:
    passthru("ls DIRECTORY_NAME"$dircontents); 
    Then you can split $dircontents by "\n" and you will get an array.

    That should work...tell me if it doesn't.
    Last edited by qslack; May 12, 2001 at 17:46.

  4. #4
    SitePoint Wizard
    Join Date
    Jul 1999
    Location
    Chicago
    Posts
    2,629
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Err, freddydoesphp got to it before me. And he came up with a better solution


Bookmarks

Posting Permissions

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