I have a file with each line of the format name=value. I need to read it using a DOS script and store all the name value pairs in memory. The names are from a predefined list of names, so I can have a list of DOS variables, and assign values to them as and when a line is read from the file. Please provide the script for doing this. I'm not able to even do as much as read a file using the below code which I got on the internet, it printes nothing: FOR /F %i IN (regfort.properties) DO @echo %i
1 Answer
This is a very simple script that sets some environment variables (names prefixed with prop_) based on the name/value pairs in the specified file, i.e. name=value in the file becomes prop_name=value in the environment:
setlocal disabledelayedexpansion
FOR /F "tokens=1* delims==" %%i IN (regfort.properties) DO set "prop_%%i=%%j"
Running set prop_ will then display the names and values of all variables with name prefix prop_.
FOR /F %%i IN (regfort.properties) DO @echo %%i. Be aware that this test only echoes the first token of each line…