I am writing a batch file to run on Windows server 2008 R2, it has a for loop in it and no matter how many tutorials I read online and try, it won’t run the for loop.
echo "Starting blur detection..."
if not exist %root%\output mkdir output
set tempnum = dir root | find /i "file"
set num = tempnum-5
for /l %idx in (0, 1, num) do (
%root%\blurDetection.exe %root%\%img%__%idx%.tif %root%\output
echo "blurDetection" %idx " of " %num )
Windows powershell says “idx was unexpected at this time.”
Any suggestions?
EDIT: Actually I think this line is causing the problem, I don’t think it is getting and integer value in return.
set tempnum = dir root | find /i "file"
(added after initial post) Oh and I missed the biggest issue. Which is indeed this line:
You mean to capture the output of
dir, right? This can, AFAIK only be done insidefor, unless you can live with outputting into a file and using that as input later.Syntax is in such a case:
Note: those are not backticks.
Best explanations for NT scripting
for: http://www.robvanderwoude.com/ntfor.phpOne more note: since you appear to rely on the file name as some number, I suspect that
dir /bwould be the better choice. Plaindirwill also output date and file size etc …IIRC names of
forvariables cannot have more than one letter. Also, inside script files (as apposed to the command line) those variables look like this:Besides, the
should probably be
Another question about
findis whether you meant to usefindstr. Too little context, butfindstrseems more natural.From
for /?:Note in particular these two statements:
%variableSpecifies a single letter replaceable parameter.FORcommand in a batch program, specify%%variableinstead of%variable.Another peculiar feature of for loops is that you can split your input and tokens will get assigned to variables in alphabetical order. So inside a
for %a ...tokens would get assigned to%a,%band so forth …set tempnum = dir root | find /i “file”