Reputation: 852
I am trying to read a file path into a Windows Batch file variable
set print_nodePath=reg query "hklm\software\node.js" /v InstallPath
for /f "skip=2 tokens=3" %%a in ('%print_nodePath%') do set nodePath=%%a
echo %nodePath%
the reg query correctly returns
HKEY_LOCAL_MACHINE\software\node.js
InstallPath REG_SZ C:\Program Files\nodejs\
but I don't know how to write the 'for' command to grab the file path since it contains a space (C:\Program). I suppose I need to join the 3rd and 4th tokens?
is there a "good" way to write this?
Upvotes: 0
Views: 308
Reputation: 34959
You need only a few modification:
tokens=3
to tokens=2*
;%%b
rather than %%a
;Here is the fixed code:
set print_nodePath=reg query "hklm\software\node.js" /v InstallPath
for /f "skip=2 tokens=2*" %%a in ('%print_nodePath%') do set "nodePath=%%b"
echo(%nodePath%
This works only if the registry value name does not contain white-spaces on its own.
Upvotes: 1