252009
 

貌似没有很优美的做法,只能把%Path%按分号分割,然后一段一段地比较。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
:InPath [In]Path [Out]0/1
SETLOCAL
SET LocalPathCopy=%PATH%
SET Result=0
:WHILE
IF "%LocalPathCopy%" == "" GOTO WEND
FOR /F "delims=;" %%I IN ("%LocalPathCopy%") DO (
    IF /I "%%~I" == "%~1" (
        SET Result=1
        GOTO WEND
    )
)
FOR /F "delims=; tokens=1,*" %%I IN ("%LocalPathCopy%") DO (
    SET LocalPathCopy=%%~J
)
GOTO WHILE

:WEND

:InPathRet
ENDLOCAL & SET %2=%Result% & GOTO :EOF

使用方法:

1
2
3
SET x=C:\Windows
Call :InPath %x% Result
IF %Result% == 0 SET Path=%Path%;%x%

您还可能感兴趣的日志:

  1. 强大的批处理 (2) Fibonacci函数
  2. 强大的批处理 (4) 使用数组
  3. 强大的批处理 (1) 字符串截取
  4. 在PowerShell中获取当前运行脚本的路径

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>