3

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
  • To run this from a batch script instead of the command prompt, double your percentage signs: FOR /F %%i IN (regfort.properties) DO @echo %%i. Be aware that this test only echoes the first token of each line… Commented Apr 11, 2011 at 8:17

1 Answer 1

3

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_.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.