I'm struggling with improving script which I proposed as an answer to How to write a batch file showing path to executable and version of Python handling Python scripts on Windows? question. To prevent Open With dialog box I'd like to read output of ftype
command, extract path of an
executable from it and check if it exists.
After this
@echo off
setlocal EnableDelayedExpansion
rem c:\ftype Python.File ->
rem Python.File="c:\path with spaces, (parentheses) and % signs\python.exe" "%1" %*
for /f "tokens=2 delims==" %%i in ('ftype Python.File') do (
set "reg_entry=%%i"
)
reg_entry's
contents is
"c:\path with spaces and (parentheses) and % signs\python.exe" "%1" %*
How do I split this to get
"c:\path with spaces, (parentheses) and % signs\python.exe"
, "%1"
and %*
?
EDIT
I tried using call
after reading Aacini's answer and it almost works. It doesn't handle %
sign, however.
@echo off
setlocal EnableDelayedExpansion
set input="c:\path with spaces and (parentheses) and %% signs\python.exe" "%%1" %%*
echo !input!
call :first_token output !input!
echo !output!
goto :eof
:first_token
set "%~1=%2"
goto :eof
Output
"c:\path with spaces and (parentheses) and % signs\python.exe" "%1" %*
"c:\path with spaces and (parentheses) and 1"