@ECHO OFF
SETLOCAL
rem The following settings for the source directory and filename are names
rem that I use for testing and deliberately include names which include spaces to make sure
rem that the process works using such names. These will need to be changed to suit your situation.
SET "sourcedir=u:\your files"
SET "filename1=%sourcedir%\Q74814659.txt"
FOR /f "usebackqtokens=1,2delims=:, " %%b IN ("%filename1%") DO IF %%b=="version" SET "version=%%~c"
ECHO version=%version%
GOTO :EOF
It's been asked before, but it's easier for me to re-write it again that look it up.
--- Revision since the JSON file is actually 1 line
@ECHO OFF
SETLOCAL
rem The following settings for the source directory and filename are names
rem that I use for testing and deliberately include names which include spaces to make sure
rem that the process works using such names. These will need to be changed to suit your situation.
SET "sourcedir=u:\your files"
SET "filename1=%sourcedir%\Q74814659_2.txt"
SET /p json=<"%filename1%"
SET "json=%json:{=%"
SET "json=%json:}=%"
FOR %%e IN (%json%) DO (
FOR /f "tokens=1,2delims=:" %%b in ("%%e") do FOR %%y IN (version description name) DO IF /i "%%y"==%%b SET "%%y=%%~c"
)
ECHO version=%version%
ECHO name=%name%
ECHO description=%description%
GOTO :EOF
rem Always verify against a test directory before applying to real data.
Read the data to json, remove all braces, process json as a comma-separated list of elements "name":"value"
Check whether the name is on the list; if so, assign the value.