I try to get a root of python executable from %PATH% with a Batch file when I print:
echo %PATH%
I get:
C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\dotnet\;C:\Program Files\Git\cmd;C:\Program Files (x86)\Common Files\Propellerhead Software\ReWire\;C:\Program Files\Common Files\Propellerhead Software\ReWire\;C:\Users\stackoverflow\AppData\Local\Programs\Python\Python37\Scripts\;C:\Users\stackoverflow\AppData\Local\Programs\Python\Python37\;C:\Users\stackoverflow\AppData\Local\Microsoft\WindowsApps;;C:\Users\stackoverflow\AppData\Local\Programs\Microsoft VS Code\bin
I need to filter that, because I want to get:
C:\Users\stackoverflow\AppData\Local\Programs\Python\Python37\
I tried to do this, but it doesn't work only print the same of echo %PATH%
for /f "tokens=* delims=;" %%a IN ("%PATH%") do (
echo "%%~a"
)
In summary, How I can get the root of python from the string of %PATH% using batch file?