IDE Script: File exist

Is there anyway to detect, using IDE Scripting, whether a file exists on a computer knowing the path to that file?

What I would like to do is be able to inform the user that a particular file is absent if it is. But I do not see a way to do this in an IDE Script.


I don’t know, why you would do this using IDE Scripting - but on MacOS you can use something like this:

[code] Dim vCommand as String = “[ -f YOUR-PATH-FILENAME ] && echo ‘Found’ || echo ‘Not found’”
Dim vResult as String

vResult = DoShellCommand ( vCommand )

print vResult[/code]

On Windows could be a simular command at shell. But I don’t know.


Thanks a lot.

Your code basically works and solves my problem.

Two things:

  1. The reason that I am doing this in an IDE Script is that my IDE script, among other things, is launching an AppleScript whose path it knows. BUT, if the user makes a mistake when entering that AppleScript path, the IDE Script that I developed just silently fails (The AppleScript is not fired off). I wanted a way to warn the user that they had entered a faulty AppleScript path.

  2. I had to make a slight modification in the code you provided because my path had (or could have) spaces in it. If one of the folders in the path has a space in it (for example: untitled folder) then your code results in a cryptic error message: binary operator expected. The cure seems to be to encase the path in double quotes. I have provided the modified code below for the sake of anyone who might run into this problem.

[code] // Dim vCommand as String = “[ -f YOUR-PATH-FILENAME ] && echo ‘Found’ || echo ‘Not found’”
Dim vCommand as String
Dim thePathName As String = YOUR-PATH-FILENAME
Dim vResult as String
Dim DQ As String
DQ = Chr(34) // This is the double quote: "

vCommand = “[ -f “+DQ+thePathName+DQ+” ] && echo ‘Found’ || echo ‘Not found’”
vResult = DoShellCommand ( vCommand )
Print (vResult)

Fortunately, in my situation, I do not have to deal with Windows.