How to? Determine a whether vars beginning with certain characters exist...

#1
Here's the code:
Code:
Do VarA In /P (Set DS_*) (
   DoSomeThingWithThatVariable %VarA
)
Works fine if variables whose names begin with "DS_" exist, produces "TCC: Z:\TestVars.btm [11] Not in environment "DS_*"" if not. While I will fully admit that this is not a serious problem, I really don't like to write batch files (or programs of any nature, for that matter) that produce error messages in "normal", totally "expected" circumstances.

So the question is simple: is there any way I can determine if any variables whose names begin with "DS_" exist before executing the loop?

- Dan
 

samintz

Scott Mintz
May 20, 2008
1,271
11
Solon, OH, USA
#2
In the few minutes I toyed with this I couldn't figure out how to get a case insensitive search to work. But other than that this works:

Code:
do VarA in /P (set | ffind /vkm /e"^[dD][sS]_") (echo %VarA)
I was looking for a switch that would turn the case sensitivity off so I could use "^DS_" or "^ds_" and not have to be concerned with the case of the environment variable.

-Scott
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
3,602
46
Albuquerque, NM
prospero.unm.edu
#4
In the few minutes I toyed with this I couldn't figure out how to get a case insensitive search to work. But other than that this works:

Code:
do VarA in /P (set | ffind /vkm /e"^[dD][sS]_") (echo %VarA)
I was looking for a switch that would turn the case sensitivity off so I could use "^DS_" or "^ds_" and not have to be concerned with the case of the environment variable.
It looks like (?i) makes it case-insensitive:

Code:
set | ffind /v /k /m /e"(?i)^ds_"
 

samintz

Scott Mintz
May 20, 2008
1,271
11
Solon, OH, USA
#5
I skipped right over that section in help at least three times. That wasn't obvious to me.

7. Extended groups

(?#...) comment​

(?imx-imx) option on/off​
i: ignore case
m: multi-line (dot(.) match newline)
x: extended form

Thanks.