Re: Get a list of folders and then get told the items in the list don't exist
Re: Get a list of folders and then get told the items in the list don't exist
- Subject: Re: Get a list of folders and then get told the items in the list don't exist
- From: Christopher Nebel <email@hidden>
- Date: Mon, 6 Oct 2003 12:03:21 -0700
On Oct 6, 2003, at 7:35 AM, Steve Thompson wrote:
Can someone tell me what I've done wrong here? Should be a simple
script but I keep getting an error and I can't see why. Basically this:
tell application "Finder"
set these_items to every folder of folder "test Master Database" of
disk "test"
repeat with i from 1 to the count of these_items
set this_item to (item i of these_items)
set the item_info to info for this_item
if folder of the item_info is true then
process_folder(this_item)
else if (alias of the item_info is false) then
process_item(this_item)
end if
end repeat
end tell
gets a list of folders as you can see, and then says the first folder
doesn't exist when it tries an "info for". I can't figure out what's
wrong with the syntax though. The line
info for disk "test"
gives the same error, Finder got an error: File some object wasn't
found
The basic difficulty is that "info for" is not a Finder command,
doesn't understand the Finder object specifiers you're feeding it, and
actually conflicts in terminology with the Finder (specifically in the
term "folder" -- it's a class in the Finder, but a property in "info
for"). The error is rather misleading; what it's trying to say is "I
can't get that object", but isn't telling you that it's because it
doesn't know how to deal with that kind of object, not because the
folder doesn't exist.
There are several ways to solve the problem. The first one is to move
the "info for" stuff out of the Finder tell block, and turn all the
Finder specifiers into aliases:
tell application "Finder"
set these_items to every folder of folder "test Master Database" of
disk "test"
end tell
repeat with i from 1 to the count of these_items
set this_item to (item i of these_items as alias)
set the item_info to info for this_item
...
end repeat
Notice the "as alias". There are a few variants on this, but they boil
down to the same thing.
Second, since all you're trying to find out is whether it's a folder,
file, or alias, you don't really need "info for" -- the Finder can tell
you that:
tell application "Finder"
set these_items to every folder of folder "test Master Database" of
disk "test"
repeat with i from 1 to the count of these_items
set this_item to (item i of these_items)
if class of this_item is folder then
process_folder(this_item)
else if class of this_item is not alias file then
process_item(this_item)
end if
end repeat
end tell
Third, all the testing is a bit silly in this case. You explicitly
asked for only folders in the first line, so everything you get back is
going to be a folder, and you don't need to check at all. (I'd believe
that you hoisted that code from someplace more general, though.)
--Chris Nebel
AppleScript Engineering
_______________________________________________
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.