Kamel Labiad Kamel Labiad - 1 year ago 110
AppleScript Question

How to check if a directory exists in ApplescriptObjc

I know the classic way how to check if a folder exists or not, in AppleScript but is didn't work for me, even if I do the error detection method it dos not work, I found online the Object-C method fileExistsAtPath but also don't know how to implement it and I also raid it is not possible, so Please help if you know any solution

my code looks like this for now

on CheckExistence(FileOrFolderToCheckString)
alias FileOrFolderToCheckString
return true
on error
return false
end try
end CheckExistence


Answer Source

The AppleScriptObjC equivalent is

use framework "Foundation"

on CheckExistence(FileOrFolderToCheckString)
   set FileOrFolderToCheckPOSIXPath to POSIX path of FileOrFolderToCheckString
   return (current application's NSFileManager's defaultManager()'s fileExistsAtPath: FileOrFolderToCheckPOSIXPath) as boolean    
end CheckExistence
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download