FSO File Collection Sorting

Results 1 to 3 of 3

Thread: FSO File Collection Sorting

  1. #1
    Join Date
    Dec 1969

    Default FSO File Collection Sorting

    Looking for ideas on how to sort the files within a folder retrieved via FileScriptingObject.<BR><BR>The default sort works fine except it for numerical order. It puts 10-19 betweem 1 and 2.<BR><BR>My code: <BR>set oFSO=Server.CreateObject("Scripting.FileSystemObje ct")<BR>set oFolder=oFSO.GetFolder("d:inetpubCompanyXRootBroch ures")<BR>set oBrochures=oFolder.Files<BR><BR>FOR EACH oBrochure IN oBrochures<BR> response.write oBrochure.Name<BR>NEXT<BR><BR>set oBrochures=nothing<BR>set oFolder=nothing<BR>set oFSO=nothing<BR><BR>Thanks in Advance

  2. #2
    Join Date
    Dec 1969

    Default RE: FSO File Collection Sorting

    You have to remember that the computer is going to sort from left to right, and doesn&#039;t care if the characters are numeric.<BR><BR>The only way around this that I know of is to prepend zeros to the beginning of the numbers, so that<BR><BR>1.txt<BR>19.txt<BR>2.txt<BR><BR>become s<BR><BR>01.txt<BR>02.txt<BR>19.txt<BR><BR>Do you dig?<BR>

  3. #3
    Join Date
    Dec 1969

    Default Or write your own sort...

    You *could* write a sorting algorithm that would detect that the file name started with a number and, if so, ignore anything but the digits and sort based on numerical value.<BR><BR>It&#039;s a hack, and you have to write the code carefully and do it all yourself, but...<BR><BR>See the ASPFAQs for how to sort a directory in the ordinary ways. Just add a custom comparison function and you are there. ("Just," he says.)

Posting Permissions

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