如何从DOS / cmd shell PATH命令中清除杂乱的输出,以便我可以读取它?

时间:2015-07-18 15:14:02

标签: windows batch-file cmd path

问题:当我在DOS或Windows cmd shell的命令行输入PATH时,我必须眯着眼睛看看我感兴趣的目录是否包含在内。我的系统示例:

PATH = C:\ ProgramData \ Oracle \ Java \ javapath; C:\ Program Files(x86)\ ActiveState Komo 编辑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 PHP \; C:\ Program Files(x86)\ Pinnacle \ Shared Files \; C:\ Program Files(x 86)\ Pinnacle \ Shared Files \ Filter \; C:\ Program Files(x86)\ nodejs \; C:\ RailsInstall 呃\的Git \ CMD; C:\ RailsInstaller \ Ruby2.1.0 \ BIN; C:\ RailsInstaller \ Ruby2.1.0 \ LIB \红宝石\ 宝石\ 1.9.1 \ BIN; C:\ RailsInstaller \的devkit \ BIN; C:\ XAMPP; C:\ XAMPP \ BIN; C:\ XAMPP \ MySQL的 \ BIN; C:\用户\用户\应用程序数据\漫游\ NPM

OUCH !!

2 个答案:

答案 0 :(得分:1)

来吧 - 那么多代码?

echo %path:;=&echo/%

或文件:

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

并作为奖金:

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

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

答案 1 :(得分:0)

解决方案:批处理文件,每行打印一个目录到控制台。作为奖励,它还会将相同的输出打印到当前目录中的文件中。


@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

<强>结果:

C:\ ProgramData \甲骨文\爪哇\ 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扩展为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 \红宝石\宝石\ 1.9.1 \ BIN
C:\ RailsInstaller \的devkit \ BIN
C:\ XAMPP
C:\ XAMPP \ BIN
C:\ XAMPP的\ mysql的\ BIN
C:\ Users \ Owner \ AppData \ Roaming \ npm

Aaaaaaahhhhhhhhh !!那更好。

我要感谢@jeb,@ ephemient和其他人在这个网站和其他地方的想法和片段,这些让我把它放在一起。希望它有所帮助。