I´m trying to traverse the PATH variable for each folder to see if a specific file is found.
Until now i´ve not succeeded to do this, and i´m wondering if someone else has a solution to this.
Sample, when the PATH variable has the content:
PATH=C:\Program Files\Application\bin;C:\PROGRA~1\APP2\EXEC;C:\Windows\System32
Can it be expanded to show on each line like :
C:\Program Files\Application\bin
C:\PROGRA~1\APP2\EXEC
C:\Windows\System32
Travers PATH variable
Moderator: DosItHelp
-
- Posts: 79
- Joined: 13 Dec 2010 10:32
Re: Travers PATH variable
Try this:
Not sure if it is the best way to do it... but, it works.
Code: Select all
@echo off
set pathvar=%path%
set searchfile=cmd.exe
:pathloop
for /f "tokens=1* delims=;" %%a in ("%pathvar%") do (
echo Searching for %searchfile% in: %%a
dir /b "%%a" 2>nul|findstr /i /r "\<%searchfile%\>">nul && echo.%searchfile% Found in %%a
set pathvar=%%b
)
if "%pathvar%"=="" goto endloop
goto pathloop
:endloop
Not sure if it is the best way to do it... but, it works.
Re: Travers PATH variable
This would work for me as well:
Regards
aGerman
Code: Select all
@echo off &setlocal
for %%a in ("%path:;=" "%") do echo %%~a
pause
Regards
aGerman
-
- Posts: 79
- Joined: 13 Dec 2010 10:32
Re: Travers PATH variable
aGerman wrote:This would work for me as well:
Code:
@echo off &setlocal
for %%a in ("%path:;=" "%") do echo %%~a
pause
I yeild to the master of batch.
Re: Travers PATH variable
Hi Guys...
Both of you, great solutions !!
ChickenSoup, more extensive, and already prepared for doing other stuff
Though i always have difficulty with traversing a variable like you do, continuing until its empty.
aGerman, quick to the point and straigh forward. superb !!
Thank you guys, both of you !!
Both of you, great solutions !!
ChickenSoup, more extensive, and already prepared for doing other stuff
Though i always have difficulty with traversing a variable like you do, continuing until its empty.
aGerman, quick to the point and straigh forward. superb !!
Thank you guys, both of you !!
Re: Travers PATH variable
xl1000 wrote:aGerman, quick to the point and straigh forward. superb !!
Thanks, but sometimes I'm much too "straight forward". At work I never have enough time for explanations and work-arounds
ChickenSoup wrote:I yeild to the master of batch.
I'm honored
I would not hesitate to declare jeb the "wise man of batch". I never found more new ideas and excelent solutions than in his postings.
Regards
aGerman
Re: Travers PATH variable
Thanks for the compliment,
but now I'm forced to show some new impressive solutions.
Perhaps I should write an AI in batch as one liner,
or maybe I should show the more complex solution of including files in batch
jeb
but now I'm forced to show some new impressive solutions.
Perhaps I should write an AI in batch as one liner,
or maybe I should show the more complex solution of including files in batch
jeb
Re: Travers PATH variable
jeb wrote:Thanks for the compliment,
but now I'm forced to show some new impressive solutions.
This was my intention.
jeb wrote:Perhaps I should write an AI in batch as one liner,
jeb wrote:or maybe I should show the more complex solution of including files in batch
Why not
Regards
aGerman