Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: %PATH% - Environment Looking for a PATH  (Read 3816 times)

0 Members and 1 Guest are viewing this topic.

nothlit

    Topic Starter


    Intermediate

    Thanked: 2
    %PATH% - Environment Looking for a PATH
    « on: October 05, 2010, 10:30:00 PM »
    Looking for a way to pull a directory out of the PATH environmental variable. Guess I'm more so looking for the drive letter. I know my path will contain \vision\bin ... I was thinking I could do a FOR loop but I'm just not getting it at midnight. Help is appreciated. :)

    Code: [Select]
    for /F "tokens=1-26 delims=;" %%a in ('echo %PATH% ^ FIND /I "\vision\bin"') do set direct=%%a
    I figured I would use delims=; to separate each path out, but then again maybe that is my problem that when I set direct %%a isn't my path? I'm not sure.

    Nevermind ... I got something to work.

    Code: [Select]
    ECHO off
    setlocal enabledelayedexpansion
     for %%G in ("%PATH:;=" "%") do (
        @echo %%G | find /I "\vision\bin" >nul
        if !errorlevel! EQU 0 set direct=%%G
     )
    setlocal disabledelayedexpansion
    if "%direct%"=="" ECHO direct equals nothing & pause
    set direct=%direct:"=%
    set direct=%direct:~0,9%
    echo "%direct%"
    Pause
    « Last Edit: October 05, 2010, 10:57:13 PM by nothlit »