良玉的博客 点点滴滴,积水成河_良玉的博客_页游、手游linux运维工程师之路

BAT批处理判断目录在%Path%中实现方法

line-height: 25.2px; background-color: rgb(255, 255, 255);">只把%Path%按分号分割,然后一段一段地比较

line-height: 25.2px; background-color: rgb(255, 255, 255);">

@echo off



echo %PATH%

SET x=C:\Windows

Call :InPath %x% Result

IF %Result% == 0 SET Path=%Path%;%x%



:InPath [In]Path [Out]0/1

SETLOCAL

SET LocalPathCopy=%PATH%

SET Result=0

echo %Result%

:WHILE

IF "%LocalPathCopy" == "" GOTO WEND

FOR /F "delims=;" %%I IN ("%LocalPathCopy%") DO (

echo %%I

  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




留言列表
发表评论
来宾的头像