ontherocks
ontherocks

Reputation: 1989

Return each item on a single line defined in %PATH% via windows command prompt

I would like to like to view each item on a single line that are defined in %PATH% environment variable. I have used the following

for %A in ("%path:;=" "%") do @echo %A

It returns each item in a single line, but with double quotes around them as shown below.

"C:\Windows\System32"
"C:\Windows\system32\Wbem"
"C:\Windows\System32\WindowsPowerShell\v1.0\"

How do I print them without the double quotes? I tried using single quotes in the command, but couldn't get it right. (There are spaces in paths in some of the entires in %PATH%)

Upvotes: 0

Views: 297

Answers (1)

Magoo
Magoo

Reputation: 80013

ECHO %path:;=&ECHO(%

:) :)


Edit for expansion.

The syntax %var:string1=string2% replaces all string1 with string2 within var hence this command is resolved to

echo directory1&echo(directory2&echo(directory3...

at each ; which is the separator used between directorynames in %path%.

The echo( is a trick construct. There are many characters which are ignored to one extent or another DIRECTLY following echo. SPACE is the most common, but the command ECHO will show the ECHO state - ECHO is on/off. ECHO( however will show nothing (other than any characters following the ( ).

As it happens, my path ends with ; so if I was to use &echo to replace ; then the line would be resolved to ....echo dirlast&echo and produce the ECHO state as a last line. Using echo( neatly overcomes this problem.

Upvotes: 3

Related Questions