JScript catch null path - help please

What is the proper way of catching an empty/null path please ?

does not explain how to in Path documentation
image

none of these work

path == null
path == ''
path == 'undefined'
path == undefined

Where/how do you get this path object ?
EDIT : Also (even if it is probably related) : what makes you think it can be null/empty/undefined ?
Under what circumstances ?

This should suffice:

!path && !String(path)

it is a file manager ? (this is what I thought it was when I bought it but apparently 'Directory Opus' is also the name of an API that interfaces with the file manager), I suspect there are many ways of getting a Path object, but Dialog.Folder is one way
image
Cancelling the folder selection diaolg from Dialog.Folder using 'cancel' or the 'close' button will give an empty/null path.

does not work
but

var name = path + '';
if ( name == 'undefined' )

does work - thought there might be a more proper way though :frowning:

You could do it this way:
if (String(folderPath) === "undefined") {

If you specifically want to know in the case of a dialog box whether the user cancelled, you could use the result property which returns 0 if it's cancelled like:

var folderPath = dlg.Folder("Select a Folder", "C:\\", true, clickData.func.sourcetab);
if (folderPath.result) {
        DOpus.Output("Selected Folder: " + folderPath);
    } else {
        DOpus.Output("User cancelled the dialog.");
    }

Awesome. Many thanks.
this works
if (path.result == 0) throw "no path chosen";

Yes :slight_smile:
I'm well aware of that. Opus provides some kind of object model you can use natively in VB Script or JScript to interact either with the system or with a large part of Opus objects.
The thing is, I don't think the Path object can ever be null, but depending on how you're getting it, it can be non relevant. That's the case with your use case (returned by a cancelled Dialog.Folder operation), would also probably be the case if you build it from FSUtil.NewPath and provide a non existing path.
In your case, the best way to deal with it has been provided by @ThioJoe by checking the result property (which by the way is described in the extensive documentation in the Scripting Reference section) :
A Path object is returned to indicate the folder chosen by the user. This object will have an additional result property that will be False if the user cancelled the dialog - the other normal Path properties will only be valid if result is True .

You appear to have found the documentation for the Dialog.Folder method but not actually read it :slight_smile:

This object will have an additional result property that will be False if the user cancelled the dialog - the other normal Path properties will only be valid if result is True .