Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

IF processing with command groups in CMDebug

Jan
179
2
I was trying to find where I had started this conversation about If's but I couldn't seem to so I'll start fresh.

These are the same IF's that I said somewhere else I couldn't get past and I didn't want to comment them out because then it get's confusing what's what. I need to get through this logic. If that's not doable in CMDebug then I'll have to go back to echo which wouldn't be ideal either.

Here's the code:

1000007279.webp


It's treating all these seperate IF structures as if they are one big IF. Execution of course goes to the last paren where I have the breakpoints. Then goes to line 29, then to 35, and on and on. Initially there were no echo's in between the IF structures. I first added a label in between them in an attempt to get CMDebug to treat the IF structures properly but no such luck. Then I took the labels (nop's) and put and echo in front so it actually had a command but it made no difference.

I downloaded the latest version of CMDebug from the site which still has the same 36.01.55 then I realized I had a later version 36.50.59 and then 36.1.55 and none of them produced the same results I was getting last night. Today not a single breakpoint on the first or last line does anything in any of these versions.

This is a big problem. One I also attempt to change from brackets to "" and other variations with no luck either.

I added a breakpoint to the echo after the first if. Still blowing through. I added a breakpoint to the last line of the IF stack, line 57, and still nothing. Went back an added a typed breakpoint before or after all the existing breakpoints. NONE ARE MID IF unless you consider the multiple IF being sucked in a structure. Absolutely not a single breakpoint is functioning.
 
And I'm going to post MS Learn documentation for validating variables.

Test if a variable is empty
To test for the existence of a command line parameter - use empty brackets like this:

IF [%1] == [] ECHO Value Missing
or
IF [%1] EQU [] ECHO Value Missing

When comparing against a variable that may be empty, we include a pair of brackets [ ] so that if the variable does happen to be empty the IF command still has something to compare: IF [] EQU [] will return True.

You can in fact use almost any character for this a '~' or curly brackets, { } or even the number 4, but square brackets tend to be chosen because they dont have any special meaning.
When working with filenames/paths you should always surround them with quotes, if %_myvar% contains "C:\Some Path" then your comparison becomes IF ["C:\Some Path"] EQU []
if %_myvar% could contain empty quotes, "" then your comparison should become IF [%_myvar%] EQU [""]

if %_myvar% will never contain quotes, then you can use quotes in place of the brackets IF "%_myvar%" EQU ""
However with this pattern if %_myvar% does unexpectedly contain quotes, you will get IF ""C:\Some Path"" EQU "" those doubled quotes, act as an escape and will break the comparison.

Test if a variable is NULL
In the case of a variable that might be NULL - a null variable will remove the variable definition altogether, so testing for a NULL becomes:

IF NOT DEFINED _example ECHO Value Missing

IF DEFINED will return true if the variable contains any value (even if the value is just a space).

To test for the existence of a variable use SET VariableName, or IF DEFINED VariableName

Test the existence of files and folders
IF EXIST filename Will detect the existence of a file or a folder.

The script empty.cmd will show if the folder is empty or not (this is not case sensitive).
 
Back
Top