set var=%%a and compare

March 11, 2010 at 09:09:00
Specs: Windows XP
Hi Guys, I’m trying to do a simple comparison between a variable that read-in from a text file against my text. This is where I’m trying to rename the existing dlls with the time and date before my ‘Auto patch.bat’ replace with the new ones, just in case if I want to roll back during testing. Any ideas would be highly appreciated.

The problem is it’s not setting the ‘ dll’ to %%A in order for me to do the comparison. It worked without the for loop. But I want to rename multiple dlls. Please point me to my mistake or feel free to suggest me a different approach.

@echo OFF & setLocal EnableDelayedExpansion
echo %date% %time%
set TIMESTAMP=%DATE:~6,4%-%DATE:~3,2%-%DATE:~0,2%_%TIME:~0,2%-%TIME:~3,2%-%TIME:~6,2%
for /f "tokens=2 delims= " %%A in (C:\Hotfix\filelist.txt) do (
set dll=%%A
echo %%A
echo "%dll:~0,2%"
if "%dll:~0,2%"==PB (
RENAME "C:\Pebble Beach Systems\Neptune\Tasks\%%b.dll" %%b.dll_"%TIMESTAMP%"
echo Rename dlls. Ready for patching.

See More: set var=%%a and compare

Report •

March 11, 2010 at 10:40:28
At first blush:

if "%dll:~0,2%"==PB

You may need double quotes on BOTH sides of ==

ALSO, you may need to escape the comma, like this:

if "%dll:~0^,2%"=="PB"

Helping others achieve escape felicity


Report •

March 11, 2010 at 13:41:29
delayed expansion issue?
echo "!dll:~0,2!"
if "!dll:~0^,2!"=="PB" (
RENAME "C:\Pebble Beach Systems\Neptune\Tasks\%%b.dll" %%b.dll_"%TIMESTAMP%"

Report •

March 11, 2010 at 14:09:44
Spot on! It was the delayed expansion issue and the missing double quotes.
Thank you for pointing out guys... Now it works.

Report •

Related Solutions

March 15, 2010 at 14:25:47
For anyone who might find this thread informative, I haven’t pass the ’,’ with ^ in line 'if "!dll:~0^,2!"=="PB" ' because I needed to trim and get the first two letters of the dlls to match my string “PB”.

Report •

Ask Question