Re: Sort Order
Re: Sort Order
- Subject: Re: Sort Order
- From: Christopher Nebel <email@hidden>
- Date: Thu, 10 Jan 2008 10:06:00 -0800
On Jan 10, 2008, at 9:02 AM, Luther Fuller wrote:
On Jan 8, 2008, at 5:45 PM, Christopher Nebel wrote:
On Jan 8, 2008, at 1:05 PM, Luther Fuller wrote:
This isn't causing a problem at the moment, but I curious ...
I have a folder containing number-named folders in OS X 10.4.11.
The Finder visibly sorts these folders in list view in the order ...
{_B,
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31
,A}
Which is alpha-numeric ordering.
I have an AppleScript that gets a list of these folders sorted by
name.
I can clearly see the folders being processed in the order ...
{1,10,11,12,13,14,15,16,17,18,19,2,20,21,22,23,24,25,26,27,28,29,3,30,31,4,5,6,7,8,9
,_B,A}
which is alphabetic ordering.
Is this an over-sight? Or is there a mysterious reason for this?
Is this a latent bug?
Traditional lexicographic ordering (what you call "alphabetic") is
how AppleScript has always worked, so we haven't changed it. (It's
not wrong, but it is a different set of rules than you want.)
However, there was a "considering" attribute added in Tiger that
changes the traditional ordering to consider numeric sequences the
way Finder does. Try enclosing your sort routine in this:
considering numeric strings
...
end
I've just done a little experimenting. It seems that 'considering
numeric strings' is not involved.
The code ...
set itemList to (sort (items of testTarget) as alias list by name)
-- sorts alpha-numerically
always returns an alpha-numerically sorted list. But the code ...
set itemList to (items of testTarget) as alias list -- sorts
alphabetically
returns an alphabetically sorted list. My test script did not use
'considering numeric strings'.
It seems that the default sort order is "alphabetical by name",
while the explicit sort-by-name order is "alpha-numeric".
Oh, I see -- I misunderstood the question. I thought you were talking
about writing your own "sort" routine that would match what Finder
shows you. (If you ever want to do that, though, "considering numeric
strings" is the way to go.)
It's a popular misconception that Finder returns "items of
folder ..." (or "files of", or whatever) in any particular order.
It's not specified that it does, and it's under no obligation to. It
really just returns them in the order that the file system stores
them. HFS+ happens to keep them in "alphabetic" order, but other disk
formats may not. If you point Finder at an NFS disk, for instance,
you'll get items in apparently random order. If you need the items to
be sorted in a particular order, you need to do that explicitly.
--Chris Nebel
AppleScript Engineering
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden