Solved If !var! EQU : (cmd for loop if statement error)

Compaq / EVO
September 12, 2017 at 07:19:29
Specs: Windows 2008 R2, 3 ghz / 16 gig ram
Hi, I have a FOR /f loop and within it I have an IF statement. I can't figure out why my IF statement fails when I run it. Please take a look. I apologise for the code as it is basic and easy for me to follow but may seem extremely simple to most of you. Please look for the line:
if !finalString1:~1,1!EQU: (


[start of code]
@echo off & cls
setLocal enableDelayedExpansion
title Network drive info _v1

echo.
set /p choice=Do you want to take snapshot of current mapped drive status? [Y/N]
if %choice% == N goto dontTakeSnapshot
if %choice% == n goto dontTakeSnapshot
if %choice% == Y goto TakeSnapshot
if %choice% == y goto TakeSnapshot
goto :eof

:TakeSnapshot
cls & echo.
net use> c:\temp\tmp_mDrives.out

:dontTakeSnapshot
set mDrivesRestore=C:\Temp\mDrivesRestore.bat
type nul> %mDrivesRestore%
c:
cd\
cd temp\
cls & echo.

echo ^@^echo off>> %mDrivesRestore%
echo cls>> %mDrivesRestore%
echo Gathering information... Please be patient.

for /f "tokens=*" %%a in (c:\temp\tmp_mDrives.out) do (
set line=%%a
set isOk=!line:~0,2!
if !isOk! EQU OK (
set stringCurrent=!line!
set stringReplaced=!stringCurrent:OK=!
set stringCurrent=!stringReplaced!
set stringReplaced=!stringCurrent:Microsoft Windows Network=!
set stringCurrent=!stringReplaced!
set stringReplaced=!stringCurrent: =!
set finalString1=!stringReplaced:~0,2!
set finalString2=!stringReplaced:~2!
echo !finalString1:~1,1!
pause
REM THE LINE BELOW SEEMS TO BE WHERE THE ISSUE IS.
if !finalString1:~1,1!EQU: (
echo net use !finalString1! !finalString2!>> %mDrivesRestore%
)
)
)
echo echo Completed mapping network drives.>> %mDrivesRestore%
echo pause>> %mDrivesRestore%
cls
echo. & echo Complete.
echo. & echo To remap network drives run %mDrivesRestore%.
pause


See More: If !var! EQU : (cmd for loop if statement error)

Reply ↓  Report •

#1
September 12, 2017 at 07:24:25
✔ Best Answer
Hi, I found the issue. I replaced the line with:

if "!finalString1:~1,1!"==":" (

and this works now. Thanks if you managed to take a look.


Reply ↓  Report •

#2
September 12, 2017 at 07:26:36
Apologies I don't know how to mark this as solved.

Reply ↓  Report •

#3
September 19, 2017 at 09:59:37
Can anyone help me here? How do I mark the answer as solved? Apologies but I have tried on Safari and Chrome and can't see any Solved buttons. Thanks

Reply ↓  Report •

Related Solutions

#4
September 20, 2017 at 03:07:59
Marked it as solved. thanks for the solution it will help others

Reply ↓  Report •

Ask Question