Basically, I want to copy the latest version of an MSI from a server to my local machine. I am trying to loop through a file and grab the first line which holds the latest version of the MSI to grab. I am not entirely familiar with the weirdness of for loops and if statements in batch files. Here is the code I have that keeps looping after it finds the first line:
cd %~dp0
mkdir "c:\MyApp\QA\msi"
rem Determine what folder is the latest version of QA
setlocal enabledelayedexpansion
dir /b /o-n "\\my-server\folder\another_folder\5.0.*" > output.txt
SET /a counter=1
SET version=""
for /f "usebackq delims=" %%a in (output.txt) do (
if "counter"==1 goto install (
xcopy "\\my-server\folder\another_folder\%%a\myinstaller.msi" "c:\MyApp\QA\msi\myinstaller.msi" /y
)
SET /a counter+=1
)
goto exit
:exit
PAUSE
In this line:
"counter"can never be equal to1. On the other hand,!counter!might.Explanation (in case you need it):
"counter"is a literal, a word counter in double quotes. You are comparing it to another literal,1. Obviously the two don’t match. What is most probably meant in that part of the script is evaluating the variablecounterand comparing the value with1. In bracketed command blocks one typically uses delayed expansion, hence!counter!(as opposed to%counter%).On a different note, the said line seems somewhat unusual. It contains the
gotocommand and another command after it. I don’t think that the command that followsgotois likely to be executed. Possiblygoto installis redundant.