How to read a file with separating pairs of name values ​​using a DOS script package?

I have a file with each line of the format name = value. I need to read it using a DOS script and save all pairs of name values ​​in memory. Names are from a predefined list of names, so I can have a list of DOS variables and assign them values ​​as and when the line is read from the file. Please provide a script for this. I can’t even make it read the file using the code I received on the Internet below, it doesn’t print anything: FOR / F% I IN (regfort.properties) DO @ echo% i

+3
source share
1 answer

This is a very simple script that sets some environment variables (prefixed names 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"

The launch set prop_will display the names and values ​​of all variables with a name prefix prop_.

+3
source

Source: https://habr.com/ru/post/1791820/


All Articles