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


[ Follow Ups ] [ Post Followup ] [ The EasyDOS Forum ] [ FAQ ]

Posted by SpywareDr on February 13, 2011 at 14:53:32:

In Reply to: How to read a file with delimitted name value pairs using DOS batch script? posted by kannan on February 13, 2011 at 10:33:31:

-- Begin VALUES.TXT file --
name1=value1
name2=value2
--- End VALUES.TXT file ---

-- Begin CMD (no BATch file needed) --
for /f %x in (values.txt) do set %x
--- End CMD (no BATch file needed) ---

Instructions:

1) Create the above VALUES.TXT file by copying and pasting the two lines above into Notepad and then saving it with a filename of VALUES.TXT. Remember where you saved it (into which folder) because you'll need to get into that folder next.

2) Get to a CMD prompt and then change into the folder where you just saved the above VALUES.TXT file.

3) Type (or copy and paste) the above command, like so:

for /f %x in (values.txt) do set %x

(and then press [Enter]).

The following two lines will now be in the environment:

name1=value1
name2=value2

4) Type:

set

(and press [Enter]) to see what's stored in your environment.

Notes:

A) If you want the above FOR command inside a BATch file, simply change the two single percent signs ("%") in the command to double percent signs ("%%"), like so:

for /f %%x in (values.txt) do @echo %%x

B) You can also use any filename you want, (instead of VALUES.TXT). If you do, simply change the VALUES.TXT filename in the FOR command to match.

C) If you do not want the SET commands to show when running the FOR command, simply put a "@" in front of SET, like so:

for /f %x in (values.txt) do @set %x




Follow Ups:



Post a Followup (use TAB key to move between boxes - NOT ENTER or RETURN)

Name:
E-Mail:

Subject:

Type your comments in the box below and SUBMIT:


[ Follow Ups ] [ Post Followup ] [ The EasyDOS Forum ] [ FAQ ]