Page 1 of 1
Scripting probs
Posted: 30 Oct 2020 12:13
by MBaas
Just to prove how much I
suck at scripting, here's my latest failure:
What I'm trying to achieve is this: I'd like to have a folder c:\Data\Journal\yymmdd. If it does not exist, it should be created. Then change dir into that folder.
Code: Select all
$dir = gettoken("c:\Data\Journal\<datea yymmdd>");
text exists($dir);
if (exists($dir) == 0) {new($dir,"dir");
goto $dir;
As the "diagnostic output" (of "2") in line 2 confirms, the dir exists. But the new($dir,"dir")-statement is executed regardless and I end up with additional folders each time I run the script. How can that be?
Re: Scripting probs
Posted: 30 Oct 2020 12:31
by highend
Why the hell do you use <datea ...> when this is not about getting a date for a selected item?
If no item is selected this would produce: <datea yymmdd> (no, it isn't resolved to anything!)
Why (even more) do you use gettoken to assign it to a variable?
This could lead to a "...\<datea" result and < is not permitted in file / folder names in Windows.
Why (...) do you mathematically add a string + the result of an expression?
And why do you leave out the closing } after the if expression?
Code: Select all
$dir = "c:\Data\Journal\<date yymmdd>";
text $dir . ": " . exists($dir);
if (exists($dir) == 0) { new($dir, "dir"); }
goto $dir;
Re: Scripting probs
Posted: 30 Oct 2020 13:55
by MBaas
Duh...more faults than lines of code!
I think part of the explanation is neuro-psychological: my brain switches into a different mode when it comes to XY-Scripting....
Thanks for your help - works like a charm!
Re: Scripting probs
Posted: 30 Oct 2020 14:00
by highend
The first two things to learn about scripting:
01. Read the help file. A lot!
02. Use e.g. step; unstep; or sysdebug; when you don't know what commands will resolve to (sysdebug if you're using
https://docs.microsoft.com/en-us/sysint ... /debugview - highly recommended!)
And thanks for the donation

Re: Scripting probs
Posted: 30 Oct 2020 15:02
by MBaas
Yeah - that "A lot!" is exactly my problem! 02 sounds like fun - but even when working nights I don't get much more time out of the day, so I fear it will be a sloooooow way...
And thanks for all the great work you do around here!
