My first suggestion is never replacing a predefined environment variable like PATH
except there is a very good reason to do it. Open a command prompt window and run set
to get output all predefined variables with their current values. Or look on Wikipedia article about environment variables the chapter Windows Environment Variables and read answers on What is the reason for '...' is not recognized as an internal or external command, operable program or batch file?
My second suggestion on needing help it is advisable to open a command prompt window and run each command used in batch file with /?
as parameter like set /?
. Then the help for the command is output on one or more pages which can be studied. How to use delayed expansion and when it must be used is explained by help of command SET on an IF and a FOR example. Other helpful pages on writing batch files are Microsoft's command-line reference and SS64.com - A-Z index of the Windows CMD command line.
My third suggestion is reading answer on How to set environment variables with spaces? and the other Stack Overflow question linked there. And the second half on this answer with details about the commands SETLOCAL and ENDLOCAL.
After studying all those help and web pages it should be no problem anymore to understand this code:
@echo off
setlocal EnableExtensions EnableDelayedExpansion
set "DataPath=D:\MeasurementData\%~n0"
for /L %%N in (1,1,5) do (
set "DateFile=%DataPath%%%N"
echo !DateFile!
pause
C:\TomoK.exe "!DateFile!" "D:\MParameter.mff" "D:\MParameter.mcf"
pause
)
endlocal
I don't know why command START was used to run the executable TomoK.exe
and therefore removed it.
However, the batch file could be also written without delayed expansion because the environment variable DataFile
is not really needed in body of loop at all. And the entire batch code above can be optimized to a single command line in batch file:
@for /L %%N in (1,1,5) do @C:\TomoK.exe "D:\MeasurementData\%~n0%%N" "D:\MParameter.mff" "D:\MParameter.mcf"
For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.
echo /?
endlocal /?
for /?
pause /?
set /?
setlocal /?
start /?