I'm using the script to create a dos batch command to run python and it is working well. I have had a couple of times where I haven't selected the folder, what with dual listers etc and I wanted to try to detect where I haven't selected anything.
I put this code in, carefully made sure that nothing was selected, and pressed the button:
DOpus.Output('DEBUG LAST folderPath: ' + folderPath)
if (folderPath === 'undefined')
{
DOpus.Output("folderPath is undefined, so return");
return;
}
and this is the result from the log:
Successfully initialized 'jscript' engine
Script started successfully
DEBUG LAST folderPath: undefined
Script completed
So the debug statement is coming out showing that folderPath is undefined, but try as I might, with double equals, treble equals and with and without quotes, I can't test positive so that I can output the message to the log and return.
DOpus.Output('DEBUG LAST folderPath: ' + folderPath);
if (typeof(folderPath) === 'undefined')
{
DOpus.Output("folderPath is undefined, so return");
return;
}
var folderPath = new String(enumFiles.item().realpath);
That is inside a loop which runs once for each item in enumFiles.
If you want to check whether the loop will run at all, and do something different if enumFiles is empty with zero items inside it, it probably makes more sense to check the size of the collection enumFiles was built around, not whether folderPath is defined after the loop.
That was exactly what I set out to do first, by putting an if test ahead of the while loop to detect if we are already atEnd, but I had no luck with a number of goes at this, so ended up with my codge to test folderPath...
Anyway here's my terrible first attempt at finding if we're already at the end, commented out to highlight it.
enumFiles = new Enumerator(tab.selected_dirs);
enumFiles.moveFirst();
//
// if nothing selected, return
//
// if (enumFiles.atEnd() == false)
// {
// DOpus.Output("Nothing selected, so return");
// return;
// }
while (enumFiles.atEnd() == false)
There's probably a method or property of enumFiles that will enable a proper test to be done.
How would I find out what properties and methods are available, if this is the right way to go?
Oh no, I just realised that I tested for false in my commented code above when I should have tested for true. Doh!
Would that have been a reasonable way to do it, or is there a better way?