slightly changing path used inside a batch file

0

Follow this please using path from registry in a batch file

Code:

for /f "tokens=2*" %%a in (' REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Web Start\1.0.1" /v Home') do set JavaPath=%%b

Output:

C:\Program Files\Java\jre8\bin

Question: Can we add x86 in this path such as it points to C:\Program Files (x86)\Java\jre8\bin ?

i tried using

for /f "tokens=* delims=\J" %%a in ( %JavaPath% ) do set path_temp = %%b 

But i get erro The system cannot find the file C:\Program.

yash

Posted 2019-09-13T06:06:41.400

Reputation: 13

tokens=* means "put the tail (which is the whole string because none separate token numbers specified) into variable %%a". delims=\J means that delimiter is both \ char and J char (not \J substring!). – Akina – 2019-09-13T06:45:32.697

Answers

0

[test.bat]

@echo off
setlocal
set JavaPath=C:\Program Files\Java\jre8\bin
echo Before: %JavaPath%
for /f "tokens=1,2* delims=\" %%a in ("%JavaPath%") do set JavaPath=%%a\%%b (x86)\%%c
echo After:  %JavaPath%

I.e. we use \ as a delimiter. So 1st token C: is set to variable %%a, Program Files to variable %%b and the tail Java\jre8\bin to variable %%c. Then we re-join them back adding both delimiters (they were removed during parsing) and <space>(x86) substring.

Akina

Posted 2019-09-13T06:06:41.400

Reputation: 2 991