追加环境变量到Path
发布时间:2020-12-14 02:43:34 所属栏目:Windows 来源:网络整理
导读:1 @echo off 2 setlocal enabledelayedexpansion 3 4 :: 使用方法: 5 :: "C:WINDOWS" 6 :: "C:jar" 7 SET x="C:jar" 8 Call :InPath %x% 9 goto :eof 10 11 12 :InPath 13 SET LocalPathCopy=% PATH % 14 :: whether exist %x% 15 IF "%LocalPathCopy%"
1 @echo off 2 setlocal enabledelayedexpansion 3 4 ::使用方法: 5 :: "C:WINDOWS" 6 :: "C:jar" 7 SET x="C:jar" 8 Call :InPath %x% 9 goto :eof 10 11 12 :InPath 13 SET LocalPathCopy=%PATH% 14 :: whether exist %x% 15 IF "%LocalPathCopy%" == "" GOTO OVER 16 GOTO WHILE 17 18 :: iterate path variable and check if the first parameter of InPath exists 19 :WHILE 20 FOR /f "delims=;,tokens=1,*" %%I IN ("%LocalPathCopy%") DO ( 21 set LocalPathCopy=%%J 22 ::echo "%%~I" == "%1" --------- "%LocalPathCopy%" 23 IF /I "%%~I" == %1 ( 24 SET Result=1 25 SET x=%%~I 26 echo %x% exists 27 GOTO OVER 28 ) 29 GOTO WHILE 30 ) 31 32 :: remove " 33 SET x=%x:"=% 34 35 IF "!Result!" == "" ( 36 echo "%x%" dont exists so we‘ll add it to path 37 :: you can use SETX command correctly if it exists 38 :: because the max length of your environment variable cant be great than 1024 39 :: SETX PATH "%Path%;%x%" 40 SET "Path=%Path%;%x%" 41 echo !PATH! 42 GOTO OVER 43 ) 44 45 pause. 46 47 :OVER 48 PAUSE & GOTO :EOF (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- windows-server-2008-r2 – Windows 2008 Unknown Disks
- windows – 使用桌面复制API捕获登录和锁定屏幕
- .net – 如何在Windows窗体应用程序中创建复合键盘快捷键?
- windows-mobile – Windows Mobile上的简易IPC?
- 如何在Windows中创建进程而不是等待它完成?
- windows-7 – 如何检索Windows 7的安装ID和确认ID?
- windows – 如何在窗口上设置HICON(.ICO有多种尺寸)?
- 从Windows命令行请求新标识
- win10完美去除小箭头
- windows-server-2003 – Windows 7不遵守DHCP的首选路由器顺