问题:当我在DOS或Windows cmd shell的命令行中inputPATH时,我必须眯起眼睛看看是否包含我感兴趣的目录。 来自我的系统的示例:
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 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)\ Mic rosoft SQL Server \ 100 \ Tools \ Binn \; c:\ Program Files \ Microsoft SQL Server \ 100 \ Tool \ 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:\ Prog (x 86)\ Pinnacle \ Shared Files \ Filter \文件(x86)\ MySQL \ MySQL Utilities \ Doctrine扩展名为PHP \; C:\ Program Files(x86)\ Pinnacle \ Shared Files \ ; 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 !!
来吧 – 那么多的代码?
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
解决方案:批处理文件,每行打印一个目录到控制台。 作为奖励,它还将相同的输出打印到当前目录中的文件中。
@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 \ 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 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 \红宝石\宝石\ 1.9.1 \ BIN
C:\ RailsInstaller \的devkit \ BIN
C:\ XAMPP
C:\ XAMPP \ BIN
C:\ XAMPP的\ mysql的\ BIN
C:\用户\用户\应用程序数据\漫游\ NPM
Aaaaaaahhhhhhhhh !! 好多了
感谢@jeb,@ephemient和其他人在这个网站和其他地方的想法和片段,让我把它们放在一起。 希望能帮助到你。