Page 1 of 1

Multiple RegEx in findstr /r /c:"RegExs"

Posted: 16 Mar 2017 14:28
by JuanMa777
Hi,
I wrote this code:

Code: Select all

@echo off
title version detection
cls
for /f "tokens=*" %%n in ('ver ^| findstr /r /c:"[ ]6"') do set ver_1="%%n"
for /f "tokens=*" %%n in ('ver ^| findstr /r /c:"[ ]10"') do set ver_2="%%n"
if /i [%ver_1%]==[] (echo Vista and older) else goto code_2
if /i [%ver_2%]==[] (echo Vista and older) else goto code_2
:code_2
echo Vista and newer!
exit


I need to put both RegEx in the same findstr, to simplify the code, and mainly to avoid this output when work with Windows 10:
Vista and older
Vista and newer,
since Windows 10 version begins with 10 and while cmd parsing the code first read "[ ]6"

Some Idea, or some alternative solution?
Thanks and regards.

Re: Multiple RegEx in findstr /r /c:"RegExs"

Posted: 16 Mar 2017 15:17
by aGerman
You need to compare both major and minor version. E.g. Vista as well as Win7 have major version 6.

Code: Select all

@echo off &setlocal
for /f "tokens=2 delims=[" %%i in ('ver') do for /f "tokens=2,3 delims=. " %%j in ("%%i") do set /a "ver=%%j*100+%%k"
echo %ver%
if %ver% leq 600 (echo Vista and older) else echo newer than Vista
pause


Steffen

Re: Multiple RegEx in findstr /r /c:"RegExs"

Posted: 16 Mar 2017 16:41
by JuanMa777
Thanks Steffen, always helping me. When I can I will contribute to the forum.
I made some minor modifications, but your answer is the correct and very usefull.
I had not thought that alternative.
Regards!