Re: getting a file list in sorted order
Re: getting a file list in sorted order
- Subject: Re: getting a file list in sorted order
- From: Bill Briggs <email@hidden>
- Date: Sun, 18 Aug 2002 17:15:15 -0300
At 12:31 AM +0100 18/08/02, Nigel Garvey wrote:
Bill Briggs wrote on Sat, 17 Aug 2002 14:56:39 -0300:
At 6:34 PM +0100 17/08/02, Nigel Garvey wrote:
Jim Brandt wrote on Sat, 17 Aug 2002 06:38:33 -0500:
> set theList to every item of alias source1 whose file type is "TEXT"
This list of aliases is not sorted alphabetically as the file list
would be shown in a list view.
tell application "Finder"
set theList to sort (every item of alias source1 whose file type is
"TEXT") by name
end tell
It may be relevant to the original poster that this sorting
operation in the finder coerces all of the aliases into Finder's file
references. That may be acceptable, but it may not be good, depending
on how he wants to process the list.
Unfortunately, a one-shot conversion using "as alias list" won't
coerce the lot back. If he wants an alias list, he'll have got to
loop through to coerce each one individually.
tell application "Finder"
set theList to sort (every item of alias source1 whose file type is
"TEXT") by name
-- set theList to (result as alias list) -- bulk coercion doesn't work
repeat with i from 1 to count of theList
set item i of theList to (item i of theList as alias)
end repeat
end tell
theList
Another approach, if aliases are required, is to remember that the
contents of a folder *are* normally returned in alphabetical order. The
order's only spoilt when something happens within the folder. (Hence the
original question.) On my machines (Mac OS 9.2.1 and 8.6) it's possible
to force a reset by opening and shutting the folder. Thus:
tell application "Finder"
tell alias source1
open
close
try
set theList to (its every item whose file type is "TEXT") as
alias list
on error
set theList to (its first item whose file type is "TEXT") as
alias as list
end try
end tell
end tell
I'd be interested to know if this works for other people and whether or
not it's faster than looping.
We talked about this off-list, and Nigel's way was faster, but I've
noted that this oddball double coercion is even faster, even when
using the loop (on my test case which had 32 text files). The case
that took 10 seconds coercing directly from file ref to alias takes
less than a second this way.
- web
set x to the ticks
tell application "Finder"
set theList to sort (every item of alias source1 whose file
type is "TEXT") by name
-- set theList to (result as alias list) -- coercion doesn't work
repeat with i from 1 to count of theList
set pathString to item 1 of theList as text
set newAlias to pathString as alias
set item i of theList to newAlias
end repeat
end tell
set n to count of theList
set y to the ticks
set elapsed to (y - x) / 60
{n, elapsed, theList}
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.