Trouble with evaluator adding terminator

I'm trying to work on an evaluator block to conditionally set file names, something like:

@set testVar={=
	pathNoExt=Parent(selpath) + Stem(selpath);

	if(IsFile(pathNoExt + ".md"))
		{Output(pathNoExt + "-2.md")}
	else
		{Output(pathNoExt + ".md")}
=}

(I just use the Output function so it outputs to the script log, i'll actually set a variable or whatever when i get it working)

But the trouble is that it's appending a terminator at the end of the stem, I guess because it thinks its the end of the path, and the ".md" is just a string:

7/18/2025 11:42:47.546 AM Evaluator:  C:\Users\Joe\Working\Temp\Test\.md

And of course it's doing it within the if condition so this is never ending up true:
if(IsFile(pathNoExt + ".md"))

I tried using Val like:
Output(Val(pathNoExt));

But that still seems to return a path type too. Is there a way in evalator to just get the raw string?

Or maybe it's thinking it's a folder path, so is there something I'm meant to do to tell it to treat it like a file path?


Also strangely, this does seem to work when using the filePath variable:

@set testVar={=if(IsFile(filePath + ".md")){Output(filePath + "-2.md")}else{Output(filePath + ".md")}=}

It doesn't append the terminator, though I didn't use the stem or anything so it just slaps it on the end of the previous extension, but the behavior is notable:

7/18/2025 11:52:37.192 AM Evaluator:  C:\Users\Joe\Working\Temp\Test.txt-2.md

I think it's because the path objects are trying to be clever and it's backfiring in this case, but you can avoid the problem by converting them to simple strings:

pathNoExt = (Parent(selpath) + Stem(selpath)) as str

Now pathNoExt + ".md" won't add the extra \.

Hm it seems to give an error for that:

Error at line 2, position 12 [Function insert]
Unknown value (6): pathNoExt

But I was able to actually figure out a solution, which is to put the path into the Format() function:

pathNoExt=Format(Parent(selpath) + Stem(selpath));

Now it works:

C:\Users\Joe\Working\Temp\Test-2.md

This was how I tested it, FWIW, in a toolbar button:

@nodeselect
{=s = (Parent(selPath) + Stem(selpath)) as str; Output(s + ".md"); return ""=}

(Then check the Script Log in a lister to see the output.)

Ah you're right it works, I left the semicolon off the end :joy:

1 Like