Re: check if a folder exists
Re: check if a folder exists
- Subject: Re: check if a folder exists
- From: JollyRoger <email@hidden>
- Date: Fri, 10 May 2002 07:04:45 -0500
On 5/9/2002 8:20 AM, "Robert Poland" <email@hidden> wrote:
>
> This is the best method I've found to date - I use it in hundreds of my
>
> scripts:
>
>
>
> -- begin script
>
> on FileExists(someFile)
>
> try
>
> set anAlias to (someFile as alias)
>
> return true
>
> on error
>
> return false
>
> end try
>
> end FileExists
>
> -- end script
>
>
>
> Use it like this:
>
>
>
> -- begin script
>
>
Tell Application "Finder"
>
>
> set testFile to (the path to the startup disk as text) & "Development:"
>
> if my FileExists(testFile) then
>
> display dialog "The folder exists."
>
> else
>
> display dialog "The folder does not exist."
>
> end if
>
>
end tell
>
>
> -- end script
>
>
I get the error, "Can't make startup disk into an item". OS 10.1.4
>
Applescript 1.7.
Robert,
I hope you won't mind me posting this to the list; because this is exactly
the reason I constantly advise new script writers to avoid tell blocks as
much as possible.
The "startup disk" command is not a Finder command; yet you are sending it
to the Finder. The Finder *should* pass the command on to the system. This
is an imperfect world, though, and the Finder is failing to pass it on and
is generating an error instead.
Even if the Finder did what it was supposed to, execution would be slower
because you are sending the command through the Finder, and the Finder is
famous for taking its sweet time to respond.
Nine times out of ten, you are better off avoiding tell blocks wherever
possible in your scripts.
JR
_______________________________________________
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.