Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

windows %PATH% variable - how to split on ';' in CMD shell again [duplicate]

I just checked stackoverflow that seemed to be very helpful and worked fine on Windows XP. But using Windows 7 it does not work for some obscure reason.

The PATH variable looks like this

C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\QuickTime\QTSystem\

It obviously contains \ as well as semicolons I use to split in a batch that contains this FOR-loop:

   FOR /F "delims=;" %%A IN ("%PATH%") DO (
      echo %%A
   )

Executing does not cause any error but it provides just one (the first) token

C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common

I had no idea why FOR terminates and played around with several variations that have been suggested on the net but none did the job.

Any help will be highly appreciated.

Christian

like image 962
Christian Avatar asked Feb 14 '13 16:02

Christian


1 Answers

You could do it this way.

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

(Source)

The problem with the way you have it is that, using the for /F switch, %%A only specifies the first token. You would have to do for /f "tokens=1-9 delims=;" %%A in ("%PATH%") and read in %%A through %%I that way.

like image 130
rojo Avatar answered Sep 18 '22 18:09

rojo