编写一个BAT档查询目前所在目录加入系统路径变量
@echo off setlocal
REM 获取当前目录的绝对路径 for %%a in ("%CD%") do set "currentPath=%%~fa"
REM 查询系统路径变量中是否已经包含当前目录 set "inPath=" for %%a in ("%PATH:;=" "%") do ( if /i "%currentPath%"=="%%~fa" ( set "inPath=true" echo %currentPath% 已经在系统路径变量中。 pause exit /b ) )
REM 如果没有包含当前目录,则添加到系统路径变量中 if not defined inPath ( setx PATH "%PATH%;%currentPath%" echo %currentPath% 已添加到系统路径变量中。 pause )
endlocal exit /b
原文地址: http://www.cveoy.top/t/topic/bLBH 著作权归作者所有。请勿转载和采集!