Caution when using the code below:
this will extract the first found number sequence in every file name and use it as the property to sort the list by
If you want to sort filenames such as
image_123_342_.jpg
the algorithm will not work (or should be adapted to accomodate more than one number sequence).

Note that the function below will skip filenames without at least one number sequence. If you need to include them as well use:

if PRegEx_Search([aItem], "[0-9]+") > 0 then
  aProp = value(PRegEx_GetMatchString())
  newList.addProp(aProp,aItem)
else
  newList.addProp(0,aItem)
end if

which will aggregate numberless filenames to the top of the list

have fun

Mark

On 6-jul-2006, at 17:11, Mark Hagers wrote:

If you could massage your date to get this format list:

[1: "a 1",10: "a 10",100: "a 100",11: "a 11",12: "a 12",2: "a 2", 21: "a 21"]

and then sort the resulting list, you'd get what you want.

As Sean points out, you could use PRegexXtra to extract the numeric part from your data:

on NumSort aList
  newList = [:]
  newList.sort()
  repeat with aItem in aList
    if PRegEx_Search([aItem], "[0-9]+") > 0 then
      aProp = value(PRegEx_GetMatchString())
      newList.addProp(aProp,aItem)
    end if
  end repeat
  return newList
end

put numSort(["a 1", "a 10", "a 100", "a 11", "a 12", "a 2", "a 21"])

-- [1: "a 1", 2: "a 2", 10: "a 10", 11: "a 11", 12: "a 12", 21: "a 21", 100: "a 100"]

Mark Hagers
[EMAIL PROTECTED]



[To remove yourself from this list, or to change to digest mode, go to 
http://www.penworks.com/lingo-l.cgi  To post messages to the list, email 
[email protected]  (Problems, email [EMAIL PROTECTED]). Lingo-L is for 
learning and helping with programming Lingo.  Thanks!]

Reply via email to