Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jun 2012
    Posts
    137
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cool reading a directory

    Is there any way of reading the contents of a directory one item at a time?
    Both scandir and readdir lists the entire contents into an array in one read.
    Is there a way to read the directory listing item by item?

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,679
    Thanks
    25
    Thanked 654 Times in 653 Posts
    readdir() does that. But remember that you start with a dot and then a double dot.
    PHP Code:
    <?php
    $dhandle 
    opendir('../googlemaps'); // Put you file here
    /*   reads first dot   */
    $fname readdir($dhandle);
    echo 
    "file name is :" $fname '<br>';
    /*   reads second dot   */
    $fname readdir($dhandle);
    echo 
    "file name is :" $fname '<br>';
    /*   reads first file name   */
    $fname readdir($dhandle);
    echo 
    "file name is :" $fname '<br>';
    closedir($dhandle);
    ?>
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #3
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,942
    Thanks
    2
    Thanked 169 Times in 164 Posts
    Hmm, why is it that a large number of questions in the mysql area (such as this one) have nothing whatsoever to do with mysql and are almost always about php? Do people really believe that php is another name for mysql?

  • #4
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,679
    Thanks
    25
    Thanked 654 Times in 653 Posts
    @FishMonger, you'll find the same thing in the PHP section asking SQl question because you use php to talk to the DB.
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."


  •  

    Posting Permissions

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