1

Problem: When I type PATH at the command line of a DOS or Windows cmd shell, I have to squint to see if the directory I'm interested in is included. Example from my system:

PATH=C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\ActiveState Komo do Edit 9\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Python27\;C :\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86 )\Common Files\Microsoft Shared\Windows Live;C:\Windows\system32;C:\Windows;C:\W indows\System32\Wbem;C:\hp\bin\Python;C:\Program Files (x86)\IVI Foundation\VISA \WinNT\Bin\;C:\Program Files (x86)\IVI Foundation\VISA\WinNT\Bin;C:\Program File s\IVI Foundation\VISA\Win64\Bin\;C:\PROGRA~2\IVI Foundation\VISA\WinNT\Bin;C:\Pr ogram Files (x86)\National Instruments\Shared\System\;c:\Program Files (x86)\Mic rosoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\Tool s\Binn\;c:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Windows\System32\ WindowsPowerShell\v1.0\;C:\Program Files\Internet Explorer;C:\Program Files (x86 )\Calibre2\;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files (x86)\My SQL\MySQL Utilities\;C:\Program Files (x86)\MySQL\MySQL Utilities\Doctrine exten sions for PHP\;C:\Program Files (x86)\Pinnacle\Shared Files\;C:\Program Files (x 86)\Pinnacle\Shared Files\Filter\;C:\Program Files (x86)\nodejs\;C:\RailsInstall er\Git\cmd;C:\RailsInstaller\Ruby2.1.0\bin;C:\RailsInstaller\Ruby2.1.0\lib\ruby\ gems\1.9.1\bin;C:\RailsInstaller\DevKit\bin;C:\xampp;C:\xampp\bin;C:\xampp\mysql \bin;C:\Users\Owner\AppData\Roaming\npm

OUCH !!

LateNiteOwl
  • 101
  • 1
  • 6

2 Answers2

2

come on - that much code?

echo %path:;=&echo/%

or for a file:

(for %%i in ("%path:;=";"%") do @echo(%%~i)>cleanpath.txt

and as a Bonus:

echo %path:;=&echo/%|sort

or

(for %%i in ("%path:;=";"%") do @echo(%%~i)|sort>cleanpath.txt
Stephan
  • 53,940
  • 10
  • 58
  • 91
  • 1
    There may be times when SORT is useful, but generally it is not a good idea because the order of the paths is important. – dbenham Jul 18 '15 at 18:04
0

Solution: Batch file that prints one directory per line to the console. As a bonus, it also prints the same output into a file in the current directory.



@echo off
setlocal EnableDelayedExpansion

@echo off

set "str=%PATH%"

REM unREM this next line to see the raw PATH output
REM echo %str%

REM use substr to replace every ';' with (the equivalent of) ';\n'
set "CleanPath=%str:;=;&echo.% "
echo.
echo %CleanPath%

echo.
set LF=^


REM !! Above blank lines are important - DO NOT DELETE THEM !!
REM Next, copy same clean path to a file, should it be desired.
REM Quietly create a file if it does not exist.
copy /y NUL CleanPath.txt >NUL 
FOR /F "tokens=* delims=;" %%i IN ("%str:;=!LF!%") DO echo %%i  >> CleanPath.txt


Result:

C:\ProgramData\Oracle\Java\javapath
C:\Program Files (x86)\ActiveState Komodo Edit 9\
C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common
C:\Python27\
C:\Program Files\Common Files\Microsoft Shared\Windows Live
C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live
C:\Windows\system32
C:\Windows
C:\Windows\System32\Wbem
C:\hp\bin\Python
C:\Program Files (x86)\IVI Foundation\VISA\WinNT\Bin\
C:\Program Files (x86)\IVI Foundation\VISA\WinNT\Bin
C:\Program Files\IVI Foundation\VISA\Win64\Bin\
C:\PROGRA~2\IVI Foundation\VISA\WinNT\Bin
C:\Program Files (x86)\National Instruments\Shared\System\
c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\
c:\Program Files\Microsoft SQL Server\100\Tools\Binn\
c:\Program Files\Microsoft SQL Server\100\DTS\Binn\
C:\Windows\System32\WindowsPowerShell\v1.0\
C:\Program Files\Internet Explorer
C:\Program Files (x86)\Calibre2\
C:\Program Files (x86)\Windows Live\Shared
C:\Program Files (x86)\MySQL\MySQL Utilities\
C:\Program Files (x86)\MySQL\MySQL Utilities\Doctrine extensions for PHP\
C:\Program Files (x86)\Pinnacle\Shared Files\
C:\Program Files (x86)\Pinnacle\Shared Files\Filter\
C:\Program Files (x86)\nodejs\
C:\RailsInstaller\Git\cmd
C:\RailsInstaller\Ruby2.1.0\bin
C:\RailsInstaller\Ruby2.1.0\lib\ruby\gems\1.9.1\bin
C:\RailsInstaller\DevKit\bin
C:\xampp
C:\xampp\bin
C:\xampp\mysql\bin
C:\Users\Owner\AppData\Roaming\npm

Aaaaaaahhhhhhhhh !! That's better.


My thanks to @jeb, @ephemient and others on this site and elsewhere for ideas and snippets that allowed me to put this together. Hope it helps.

LateNiteOwl
  • 101
  • 1
  • 6