Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read a file with delimitted name value pairs using DOS batch script?

Tags:

file

dos

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

like image 665
Hugh Darling Avatar asked Dec 09 '25 12:12

Hugh Darling


1 Answers

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

like image 200
mousio Avatar answered Dec 11 '25 09:12

mousio



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!