通过批处理从%path%变量中删除不需要的路径名 [英] Remove unwanted path name from %path% variable via batch

查看:320
本文介绍了通过批处理从%path%变量中删除不需要的路径名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

范围:Windows XP或更高版本 工具:批处理脚本

Scope: Windows XP or newer Tools: Batch script

我需要能够从系统%PATH%变量中删除不需要的路径名.我知道如何使用诸如SETX.EXE之类的工具向系统%PATH%变量添加新的路径名,这也使它立即在现有CMD环境中可用.这可能是使用FIND和/或某种FOR循环的问题,但是我不太确定如何完成此操作.这是示例路径声明...

I need to be able to remove an unneeded path name from the system %PATH% variable. I know how to add a new path name to the system %PATH% variable, using a tool such as SETX.EXE, which also makes it immediately available within the existing CMD environment. It's probably a matter of using FIND and/or a FOR loop of some kind, but I'm not quite sure how to accomplish this. Here's a sample path statement...

%PATH% = C:\;C:\Program Files\Common Files\Java;C:\oracle\product\10.2.0\bin;C:\WINDOWS;C:\WINDOWS\system32;

由此,我需要能够删除与"oracle"相关的完整路径名.因此,在上面的示例中,我需要能够从上述路径语句中删除"C:\ oracle \ product \ 10.2.0 \ bin".不幸的是,不仅oracle路径名与上面显示的不同,而且可能有多个oracle路径名,并且都需要删除.我尝试在此处实施解决方案...

From this, I need to be able to remove the full path name related to "oracle." So, in the above example, I need to be able to remove the "C:\oracle\product\10.2.0\bin" from the above path statement. Unfortunately, not only could the oracle path name be different than shown above, there could be multiple oracle path names and all need to be removed. I tried implementing the solution here...

如何提取PATH环境变量中的完整路径?

但是,它不起作用.该脚本找不到路径名.任何帮助,将不胜感激.谢谢.

However, it just isn't working. The script wouldn't find the path name. Any help would be appreciated. Thank you.

推荐答案

您可以尝试以下方法:

@echo off&cls
setlocal EnableDelayedExpansion
set $line=%path%
set $line=%$line: =#%
set $line=%$line:;= %

for %%a in (%$line%) do echo %%a | find /i "oracle" || set $newpath=!$newpath!;%%a
set $newpath=!$newpath:#= !
echo set path=!$newpath:~1!

我在最后一行放了echo.检查结果,如果可以,请删除它.

I putted an echo to the last line. Check the result and If it's OK for you, remove it.

这篇关于通过批处理从%path%变量中删除不需要的路径名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆