Re: How to test if a dropped item (on open) is a file or folder
Re: How to test if a dropped item (on open) is a file or folder
- Subject: Re: How to test if a dropped item (on open) is a file or folder
- From: Paul Berkowitz <email@hidden>
- Date: Wed, 03 Jul 2002 08:57:01 -0700
On 7/3/02 8:11 AM, "Spunk S. Spunk III" <email@hidden> wrote:
>
Hi all,
>
>
I can't quite figure out the syntax for testing whether a dropped item is a
>
file or a folder. Everything I've tried gets an errors "can't get {kind or
>
type or class, etc} of [alias] Path:to:my:fileOrFolder". I've tried
>
referencing the alias (returned from the dropped item) directly as well as
>
"as string" but nothing seems to work. Eg.
>
>
on open (filesOrFolders)
>
set numOfItems to (count of filesOrFolders)
>
>
-- handle only one file/folder being dropped
>
if numOfItems is equal to 1 then
>
set item1 to filesOrFolders as string -- optional line
>
-- if (kind of filesOrFolders ) is "folder" then -- tried this too
>
if (kind of item1) is "folder" then
>
display dialog "You dropped a folder!"
>
...
>
end if
>
end open
>
>
I've tried a million other variations as well. I need to know if the dropped
>
items are files or folders...
>
Have any of these million variations involved either 'info for' standard
addition or the Finder, neither of which you reference in the script above?
Reading their Dictionaries will help:
on open (filesOrFolder)
repeat with I from 1 to (count filesOrFolders)
set theItem to item i of filesOrFolders
if folder of (info for theItem) then
--do folder stuff, including recursive
else -- a file
-- do file stuff
end if
end repeat
end open
The result of 'info for' is a record of various properties of type 'file
information'. 'file information' has its own listing in the Standard
Additions dictionary, where you will see tat one of its properties is
'folder', of boolean type.
As a rough and ready rule, if something looks as if it might be handled by
either a Standard Addition or the Finder, go with the addition. It's usually
trouble-free. And don't expect terms like 'kind' to work in pure
AppleScript, outside the Finder. Check the ASLG when in doubt for pure
AppleScript, and the current Finder and Standard Additions dictionaries for
their terms.
Glad to see you're asking in the right forum.
--
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.