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: Steven Angier <email@hidden>
- Date: Mon, 19 Aug 2002 09:19:41 +1000
On 19/8/02 3:13 AM, "has" <email@hidden> wrote:
>
Steven Angier wrote:
>
>
> 1. Use the Macscript.com Library as it has several functions for listing
>
> files and folders, including 2 that filter in only the supplied file and/or
>
> creator types:
>
[...]
>
> set theList to FilterFiles(source1,"TEXT",{})
>
>
What benefits does this have over using the Finder's 'whose' clause to
>
filter by? (Assuming this isn't already what it does internally - you seem
>
to infer below that it doesn't.) It's hard to beat, short of going outside
>
AS to do so.
I implied; you inferred :-) It is the case that the Finder is not used in
any of the Macscript.com Library file listing functions. The distinct
advantage is that it works; reliably. IMHO, code that works slowly in all
situations is far better than code that works quickly but only 90% of the
time.
>
> 2. If you must (or want to) do things yourself, AVOID USING THE FINDER
>
> WHENEVER POSSIBLE. The Finder still craps out from time to time when sorting
>
> or when getting long or recursive directory listings (stack overflows).
>
>
This seems a bit alarmist, imho.
It is. Again, code that works slowly in all situations is far better than
code that works quickly but only 90% of the time; and code that doesn't work
in certain situations should not be used unless the code guards against
those specific situations where it will fail.
>
The problems with 'entire contents' are
>
known (I don't suppose this has been fixed in OS X then?). Bit
>
disappointing to learn that 'sort' also has stack overflow problems though
>
(sounds like some basic recursive sorting algorithm with inadequate
>
protection against this sort of thing; tsk). Mmmm... maybe the reason
>
'sort' hasn't yet been implemented in Finder/OSX is that they're planning
>
something more robust? [Just a hope.]
>
>
All the same, I don't think Finder scripting is _that_ problematic, and
>
other stuff seems to work fine.
If you say so.
>
[Most problems that arise on the lists seem
>
to be with folk having difficulty figuring out how to do things - probably
>
because the documentation doesn't explain it very well - not because
>
they're running into Finder bugs.]
I think that when dealing with the Finder it is more the overall fussiness
of the Finder objects and events that throws new scripters, compounded by
the Finder's use of terms such as "file".
The classic example is to time how long it takes a new scripter to figure
out how to script the Finder to create a folder.
>
> The "list folder" command (upon which all Macscript.com Library file listing
>
> functions is based) returns file names sorted alphabetically. It returns a
>
> list of names which you have to concatenate with the parent folder path, and
>
> test the type and/or creator.
>
>
>
> This method maybe slower than using the Finder, but at least you get the
>
> right answer.
>
>
Mmmm... I did some checking (OS9.2.2./AS1.6). Depends what you're
>
definition of "right answer" is: I found that 'list folder' can include
>
the Desktop Folder (the Finder doesn't), and it has different ideas about
>
ordering; for example, an underscore has precedence over an alphabetical
>
character [1], which in AS and the Finder it does not.
I didn9t realise that the Finder "hides" the desktop folder in this way.
IMHO, this is another strong reason for avoiding its use. Perhaps the Finder
also hides things such as Temporary Items?
>
======================================================================
>
>
Again though, this seems a pretty inefficient way of performing a very
>
simple task that's so easily [and quickly] performed using the Finder and a
>
simple 'whose' clause [8 lines of code versus 1, plus a whole bunch of
>
relatively slow AS operations and osax calls].
I presented an option of doing it on one line:
FilterFiles(theFolder, theAllowableTypeList, theAllowableCreatorList)
>
You only really want to use such things when you're going to get some
>
worthwhile benefits from it, doing things that you can't do with the Finder
>
alone (e.g. filter files according to content, or processing items as you
>
go).
The worthwhile benefit is the peace of mind that list folder is reliable.
Steven Angier
Macscript.com
_______________________________________________
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.