Remove unwanted path name from %path% variable via batch

前端 未结 4 1638
青春惊慌失措
青春惊慌失措 2020-12-01 05:15

Scope: Windows XP or newer Tools: Batch script

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

4条回答
  •  南笙
    南笙 (楼主)
    2020-12-01 05:59

    You can try something like this :

    @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!
    

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

提交回复
热议问题