Does anyone have a snippet of code to test if a folder exists? I have tried writing this, but cannot get it to work. I used “if (foldertest exists) then” and “if not(foldertest exists)”, but I cannot prove it it is true or false with these statments.
tell application "Finder"
if exists folder "path:to:folder:" then
-- it exists, do something
else
--it doesn't exist, do something else
end if
end tell
Here’s a handler similar to Jon’s that does some additional parameter-checking. Got this from the applescript-users mailing list:
on testPathExists(inputPath)
-- version 1.5
-- from Richard Morton, on applescript-users@lists.apple.com
-- public domain, of course. :-)
-- gets somewhat slower as nested-depth level goes over 10 nested folders
if inputPath is not equal to "" then try
get alias (inputPath as string) -- just in case inputPath was not string
return true
end try
return false
end testPathExists