Kamel Labiad Kamel Labiad - 2 months ago 18
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)
try
alias FileOrFolderToCheckString
return true
on error
return false
end try
end CheckExistence


Thanks

Answer

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