Checking if a folder 'exists' in Finder

Hi there,

Please can someone help me with this small query. I’m trying to find out if a folder exists in a particular folder. I’ve already done this by getting he contents of the folder and looping through all the names, but I wanted to try and shorten it and make it look a little more tidy.

Here’s the sort of thing I’m trying to do:-

tell application "Finder"
  if exists (folder whose name is "NAME" as text) of folder "MAC HD:FOLDER:FOLDER:" then
	-- DO THIS
  end if
end tell

I’ve tried a number of variations on this but I think I must be getting my references wrong or syntax mixed up.

Please can someone help.

Thanks

Nick

Hi Nick,

it’s easier:

tell application "Finder"
	if exists folder "MAC HD:FOLDER:FOLDER:" then
		-- DO THIS
	end if
end tell

or without the Finder:

try
	"MAC HD:FOLDER:FOLDER:" as alias
	-- DO THIS
end try

Hi Stefan,

Thank you for your reply and for the two examples. :slight_smile:
I like the method without using the Finder.

I’d started off way too complicated. :expressionless:

Thanks again,

Regards,

Nick

Hi Nick,

If you’re finding a folder named “NAME” in another folder, you don’t need filter reference form. Just use the mixed reference:

tell application “Finder”
if exists folder “NAME” of folder “MAC HD:FOLDER:FOLDER:” then
– DO THIS
end if
end tell

Hi Kel,

Thanks for your reply and for the example.
It’s useful to see another way of looking at things.

Regards,

Nick

Hi Nick,

It’s not another way of looking at it. It looks like, from the script you posted, that you were looking for a folder named “NAME” inside folder “MAC HD:FOLDER:FOLDER:”

(folder whose name is “NAME” as text) of folder “MAC HD:FOLDER:FOLDER:”

and using the filter reference form rightly would not be necessary.

Maybe Stefan forgot to put the “NAME” folder in the path.

gl,

Hi Kel,

Thanks again for your reply.
Yeah, I’d noticed the folder name missing in Stefans example and so put one in and it worked fine.

Regards,

Nick

This has been covered many times, including once in the past week:

http://bbs.applescript.net/viewtopic.php?pid=76387