Re: file list with Finder
Re: file list with Finder
- Subject: Re: file list with Finder
- From: Paul Berkowitz <email@hidden>
- Date: Sat, 12 Oct 2002 00:28:36 -0700
On 10/12/02 12:00 AM, "Gakuji Ohtori" <email@hidden> wrote:
>
On 2002.10.12, at 01:49 PM, Gakuji Ohtori wrote:
>
>
> One workaround is to use "as list" such as
>
>
>
> set theFolder to choose folder
>
> tell application "Finder"
>
> files in (entire contents of theFolder as list)
>
> end tell
>
>
Sorry, I just found out that this workaround still causes an error when
>
theFolder contains one or more items. Any workarounds?
There were two different errors:
1) It's very common in many apps that certain properties have to first be
evaluated before you can get a property of the property. There are usually
three ways to evaluate - you found one of them. But they are not applicable
here. The three ways re:
a) set a variable to the (first) property, then get its property in the
next line:
tell application "Finder"
set allContents to (entire contents of theFolder)
item 1 of allContents
end tell
b). Best way. Use the explicit 'get'
tell application "Finder"
item 1 of (get entire contents of theFolder)
end tell
c) Coerce to another data type (the way you found).
tell application "Finder"
item 1 of (entire contents of theFolder as list)
end tell
All these will work.
2.) The error of your script:
set theFolder to choose folder
tell application "Finder"
files in (entire contents of theFolder as list)
end tell
is that
(entire contents of theFolder as list)
and
(get entire contents of theFolder)
and even
(entire contents of theFolder)
all result in an AppleScript list. The Finder can't get files in an
AppleScript list, it can only get files in a folder or disk (container): its
own application objects which can have files "in" them.
So if you use one of the three valid ways of evaluating the list, you are
getting {} - but by "accident". It probably should error, instead you get
{} as one of those somewhat misleading Finder coercions. It means that the
syntax is OK, but the list "has no files" - which it doesn't: it has only
list items. (And don't try 'item' in a Finder block, since 'item' means
something different to the Finder.)
In any case, if you are planning to use a recursive handler to go through
the whole tree, why are you using 'entire contents'? It won't give you the
means to do that. You need to go folder by folder. Get every file and every
folder of each folder, and look in each folder for more. I hope this tree
isn't too big.
--
Paul Berkowitz
_______________________________________________
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.