1.

Solve : %PATH% - Environment Looking for a PATH?

Answer» <html><body><p>Looking for a way to pull a directory out of the <a href="https://interviewquestions.tuteehub.com/tag/path-11833" style="font-weight:bold;" target="_blank" title="Click to know more about PATH">PATH</a> environmental <a href="https://interviewquestions.tuteehub.com/tag/variable-772077" style="font-weight:bold;" target="_blank" title="Click to know more about VARIABLE">VARIABLE</a>. Guess I'm more so looking for the drive letter. I know my path will <a href="https://interviewquestions.tuteehub.com/tag/contain-409810" style="font-weight:bold;" target="_blank" title="Click to know more about CONTAIN">CONTAIN</a> \vision\bin ... I was thinking I could do a FOR loop but I'm just not getting it at midnight. Help is appreciated. <br/><br/> Code: <a>[Select]</a>for /<a href="https://interviewquestions.tuteehub.com/tag/f-236701" style="font-weight:bold;" target="_blank" title="Click to know more about F">F</a> "tokens=1-26 delims=;" %%a in ('echo %PATH% ^ <a href="https://interviewquestions.tuteehub.com/tag/find-11616" style="font-weight:bold;" target="_blank" title="Click to know more about FIND">FIND</a> /I "\vision\bin"') do set direct=%%a<br/>I figured I would use delims=; to separate each path out, but then again maybe that is my problem that when I set <strong>direct</strong> %%a isn't my path? I'm not sure.<br/><br/>Nevermind ... I got something to work. <br/><br/> Code: <a>[Select]</a>ECHO off<br/>setlocal enabledelayedexpansion<br/> for %%G in ("%PATH:;=" "%") do (<br/>    echo %%G | find /I "\vision\bin" &gt;nul<br/>    if !errorlevel! EQU 0 set direct=%%G<br/> )<br/>setlocal disabledelayedexpansion<br/>if "%direct%"=="" ECHO direct equals nothing &amp; pause<br/>set direct=%direct:"=%<br/>set direct=%direct:~0,9%<br/>echo "%direct%"<br/>Pause</p></body></html>


Discussion

No Comment Found