Checking for a file - Finder or Shell

I need to loop through a whole lot od d/b records and check if a file (path) is valid and flag if not. I’ve got 2 working methods…

1 Finder

--snippet
if not my TestPreviewPath(preview_path) then
	tell record id aRecord
		set value of field "Keywords" to "MISSING_PREVIEW"
	end tell
end if

on TestPreviewPath(thePath)
	tell application "Finder"
		if (thePath exists) then
			set the theCheck to true
		else
			set theCheck to false
		end if
		return theCheck
	end tell
end TestPreviewPath
  1. shell
-- snippet
if my TestPOSIXPreviewPath(preview_path) = "false" then
	tell record id aRecord
		set value of field "Keywords" to "MISSING_PREVIEW"
	end tell
end if

on TestPOSIXPreviewPath(thePath)
	set theReply to (do shell script "[ -e '" & thePath & "' ] && echo true || echo false ")
	return theReply
end TestPOSIXPreviewPath

I’m assuming the shell is likely faster, or doesn’t it make a difference. Might I do this more efficiently?

TIA

I prefer the shell method. The shell method can be used while the finder is hanging or not running at all. I only use tell app blocks if i really need that application.

I’m the opposite of DJ Bazzie Wazzie. I use an applescript method over a shell method most of the time. The reason being is that there’s overhead with “do shell script” (meaning it takes more time) so applescript methods are usually faster. Of course there’s exceptions so the best approach is to time the methods so you know which is fastest. There’s timing threads on here that show how.

In your case I agree that you should avoid the Finder if possible. So for your task I would use the following applescript method. This works because an alias must exist or it errors.

on TestPreviewPath(thePath)
	try
		alias thePath
		return true
	on error
		return false
	end try
end TestPreviewPath