Results 1 to 5 of 5
  1. #1
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    Vancouver, Br. Columbia, Canada
    Posts
    632
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Sorted directory listing (97 / 2002)

    I wrote an application that uses the Dir() function to find all the JPG files in a folder and does some processing on them. It does its job, but now I find that it's important to process the files in alphabetic order. Help for Dir() states that Dir() returns the files in no particular order, and its up to the programmer to sort the list manually using an array. I think I can do this, but it seems a bit clunky, and was wondering what other people do when confronted with the same requirement. Comments?

    PS. I searched Google etc for a class module that would do this task, but came up empty. Does anybody have some code that can be dropped into an existing application that I could use? Thanks.
    --------------------------------------------------
    Jack MacDonald
    Vancouver, Canada

  2. #2
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Sorted directory listing (97 / 2002)

    Why don't you search on google to find SORT.

    An alternative is to append these filename entries to a table, then use a query or SQL code to read thru the table in filename order.

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Sorted directory listing (97 / 2002)

    This newsgroup post demonstrates how to use FileSystemObject from the Scripting library together with a disconnected ADO recordset to sort the directory listing.

    More ideas in the thread starting with <post#=343243>post 343243</post#>.

  4. #4
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: Sorted directory listing (97 / 2002)

    If interested, see attached sample database (A2K format). Form frmListFiles has a listbox that lists files with specified file spec, from specified folder, in alphabetical order. A callback function (LoadFileList) is used to populate list; the file list is generated using DIR function (see GetFileList function); the file list is sorted using a standard-issue QuickSort (see QuickSortArray sub). These functions performed efficiently in testing, even with large numbers of files in a directory. When form opens, default file spec is "C:*.*", this can be modified to suit other purposes.

    HTH
    Attached Files Attached Files

  5. #5
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    Vancouver, Br. Columbia, Canada
    Posts
    632
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Sorted directory listing (97 / 2002)

    Thanks Mark. That fits the bill exactly.
    --------------------------------------------------
    Jack MacDonald
    Vancouver, Canada

Posting Permissions

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