SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You saw the subject. I'm reading a directory's contents with readdir(), and need to sort the file-names alphabetically, if that's possible.

    Any simple way to do this?

  2. #2
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Check out the code in this thread (particualry freddydoesphp's code and my posts.

    http://www.sitepointforums.com/showt...5&pagenumber=2

  3. #3
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Chris that thread maybe overkill for what you need, so here is a basic exmaple, you probably won't even need to sort them since the directoy is listed in alphabetical order already and so your array shouldalreay be alphabetized, but I threw it in for extra care. BTW use dir() instead of readdir() like I did.

    PHP Code:
    <?
    $dir 
    dir(".");
    while(
    $file $dir->read()) {
        if ((
    $file != ".") && ($file != "..")) {
            
    $files[] = $file;
            }
        }
    sort($files);
    foreach(
    $files as $key => $val) {
        print 
    "$val<br>";
        }
    ?>
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  4. #4
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My mistake -- I am using dir(), and then readdir(), I think. I dunno, I'm confused.

    Thanks for your help, both Louie and Sid. I think I'm going to work-around this with SQL -- much easier for me in the long-run, but I am definintely going to save that code Freddy -- I'm sure it will come in handy.

    You the man - thanks!

  5. #5
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi, sorry, I just linked to that thread because I was literally heading off to bed and was too lazy to think straight


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
  •