0

I'm trying to parse my "Path" environment variable with a Batch line command. What I would like to achieve is having each substring of the "Path" variable to be printed on a different line.

With the following, I can print each token of the "Path" using semicolon ";" as a separator :

For /F "tokens=* delims=;" %i in ("%Path%") do @echo %i

but my output is C:\blabla1\bin C:\blabla2\bin C:\blabla3\bin C:\blabla4\bin . I would like to concat the carriage return, but I'm not able to do that.

Any suggestions? Thanks

p.s. I would like to achieve this within a single command line, avoiding to use a script saved in a separate .bat file

Ren0
  • 29
  • 1
  • 6

2 Answers2

3

assuming you don't have a path with ; in it's name try this:

@ECHO OFF &SETLOCAL
SET "mypath=%path%"
SET mypath=%mypath:;=";"%
FOR %%a IN ("%mypath%") DO ECHO %%~a
Endoro
  • 37,015
  • 8
  • 50
  • 63
0
Call :Entry %Path%
GoTo :EOF

:Entry
For /F "Tokens=1,* Delims=;" %%i In ("%1") Do (
    Set Entry=%%i
    Set Remaining=%%j
)
Rem Do something with %Entry% ...
If Defined Remaining Call :Entry %Remaining%
GoTo :EOF
LS_ᴅᴇᴠ
  • 10,823
  • 1
  • 23
  • 46
  • I've read many times about using %%i , but it is not working for me. I'd rather use %i, but I didn't actually get the difference. Using your script with %%i returns " %%i was unexpected at this time" . Thanks for the answer – Ren0 Jul 24 '13 at 15:29
  • there is a nice answer from jeb [here](http://stackoverflow.com/a/5472168/2098699). – Endoro Jul 24 '13 at 15:56