I tried to implement it very similar to the PATH command as much as possible. But some of existing bug in the dos-shell doesn't allow to complete them. In any way, the script (written in batch completely) does the requested features:
-- remove certain paths
-- remove paths matching the specified pattern (if the directory is starting with the defined pattern)
-- clean up the PATH
-- show the existing PATH
Removing is performed for the current environment only and is not kept in the system permanently for all processes.
Code: Select all
::Displays or unsets a search path for executable files.
::
::UNPATH [[/S|/L] path] ...
::UNPATH PATH
::
::Type UNPATH PATH to clear all search-path settings snd direct cmd.exe to
::search only in the current directory. It is similar to PATH ;.
::
::Type UNPATH without parameters to display the current path.
::
::Type a set of directories to be removed from the PATH. Use switches to
::modify behavior of the command:
:: /S - Tells to remove all entries starting with the path
:: /L - Tells to remove the exact match of the path (by default)
@echo off
if "%~1" == "/?" (
for /f "tokens=* delims=:" %%a in ( 'findstr /b "::" "%~f0"' ) do echo:%%a
goto :EOF
)
if "%~1" == "" (
path
goto :EOF
)
if /i "%~1" == "path" (
path ;
goto :EOF
)
setlocal
set "unpath_subdir="
for %%a in ( %* ) do call :unpath_arg "%%~a"
if defined PATH set "PATH=%PATH:~1%"
endlocal & set "PATH=%PATH%"
goto :EOF
:unpath_arg
if "%~1" == "" goto :EOF
if /i "%~1" == "/S" (
set "unpath_subdir=1"
goto :EOF
)
if /i "%~1" == "/L" (
set "unpath_subdir="
goto :EOF
)
for /f "tokens=*" %%s in ( "%PATH:;=" "%" ) do (
set "PATH="
for %%p in ( "%%s" ) do call :unpath_entry "%%~p" "%~1"
)
goto :EOF
:unpath_entry
if "%~1" == "" goto :EOF
if /i "%~1" == "%~2" goto :EOF
set "unpath_entry=%~1"
call set "unpath_entry=%%unpath_entry:%~2=%%"
if /i "%~1" == "%~2%unpath_entry%" if "%unpath_entry:~0,1%." == "\." if defined unpath_subdir goto :EOF
set "PATH=%PATH%;%~1"
goto :EOF
If the community found the script useful I would updated the topic with the actual version of the script. In any way all of you can find the latest version following by the link http://code.google.com/p/cmd-bat/source ... unpath.bat