Copyright © 2003-2012 by Prof. Timo Salmi  
Last modified Tue 14-Aug-2012 18:04:01

Assorted NT/2000/XP/.. CMD.EXE Script Tricks
From the html version of the tscmd.zip 1cmdfaq.txt file
To the Description and the Index

This page is edited from the 1cmdfaq.txt faq-file contained in my tscmd.zip command line interface (CLI) collection. That zipped file has much additional material, including a number of detached .cmd script files. It is recommended that you also get the zipped version as a companion.

Please see "The Description and the Index page" for the conditions of usage and other such information.

115} How can I decompose the path to be one folder per line?

With G(nu)AWK
  @echo off & setlocal enableextensions
  echo %path%;^
    |gawk -F; "{for (i=1;i<=NF-1;++i) printf \"%%s\n\",$i}"
  endlocal & goto :EOF

The output might be e.g.
  C:\Program Files\TSEPro
  C:\Program Files\010Editor
  C:\Program Files\QuickTime\QTSystem\
  C:\Program Files\SSH Communications Security\SSH Secure Shell

With SED
  @echo off & setlocal enableextensions
  path | sed -e s/.*=// -e s/;/\r\n/g
  endlocal & goto :EOF

Or with straight script
  @echo off & setlocal enableextensions
  for /f "tokens=1-15 delims=;" %%a in ("%path%") do (
    if not [%%a]==[] echo %%a
    if not [%%b]==[] echo %%b
    if not [%%c]==[] echo %%c
    if not [%%d]==[] echo %%d
    if not [%%e]==[] echo %%e
    if not [%%f]==[] echo %%f
    if not [%%g]==[] echo %%g
    if not [%%h]==[] echo %%h
    if not [%%i]==[] echo %%i
    if not [%%j]==[] echo %%j
    if not [%%k]==[] echo %%k
    if not [%%l]==[] echo %%l
    if not [%%m]==[] echo %%m
    if not [%%n]==[] echo %%n
    if not [%%o]==[] echo %%o
    )   endlocal & goto :EOF

Exceptionally for this FAQ a pure Visual Basic Scripting (i.e a non-batch aided solution) is of particular relevance because the environment in a CLI might differ (you may have added some folders or other customized the path, as I have done). The VBS solution gives your regular path.
  ' SHOWPATH.VBS by Prof. Timo Salmi
  ' Last modified Wed 11-Jun-2008

  Sub GetAndShowPath()
    dim s, n, m, myPath, rest
    Set WshShell = WScript.CreateObject("WScript.Shell")
    Set WshSysEnv = WshShell.Environment("SYSTEM")
    m = 1
    n = 1
    rest = myPath & ";"
    Do While n > 0
      n = Instr(1,rest,";")
      if n = 0 Then Exit Do
      s = s & Mid(rest,1,n-1) & vbCrLf
      m = n + 1
      rest = Mid(rest,m)
    WScript.Echo s & vbCrLf & myPath
  End Sub 'GetAndShowPath

  Sub MainProgram()
  End Sub 'MainProgram

However, as pointed out by Ralph Brown to me, the actual task can be done in just one line of pure script:
  echo %path:;=&echo.%

References/Comments: (If a Google message link fails try the links within the brackets.)
  Google Groups Sep 10 2005, 2:10 am [M]
  Google Groups Sep 10 2005, 12:23 am [M]
  Google Groups Sep 26 2005, 9:31 pm [M]