<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Серый форум &mdash; CMD/BAT: удаление путей из переменной PATH]]></title>
		<link>https://forum.script-coding.com/viewtopic.php?id=9231</link>
		<atom:link href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=9231&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «CMD/BAT: удаление путей из переменной PATH».]]></description>
		<lastBuildDate>Fri, 07 Feb 2014 20:20:43 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[CMD/BAT: удаление путей из переменной PATH]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=79847#p79847</link>
			<description><![CDATA[<p>Полагаю, что все понимают важность и необходимость перменной PATH. Понадбилось реализовать как можно блее простой способ удаления заданных путей из переменной PATH. Сделал&nbsp; делюсь, встречайте скрипт UNPATH, который<br />-- удаляет заданные пути из PATH<br />-- удаляет пути соответствующие шаблону<br />-- очищает PATH полностью<br />-- отображает содержимое</p><p><em>Удаление производится только для текущего окружения и не сохоаняется в системе для всех процессов. </em></p><p><strong>Примеры</strong><br /></p><div class="codebox"><pre><code>
:: показать текущее содержимое
UNPATH

:: удалить только c:\windows
UNPATH c:\windows

:: удалить все, что начинается на c:\windows
UNPATH /s c:\windows

:: удалить все, что начинается на c:\Program Files
:: удалить только c:\windows
UNPATH /s &quot;C:\Program Files&quot; /l c:\windows

:: очистить PATH (аналогично PATH ;)
UNPATH PATH
</code></pre></div><p><strong>Исходный код</strong><br /></p><div class="codebox"><pre><code>
::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 &quot;%~1&quot; == &quot;/?&quot; (
    for /f &quot;tokens=* delims=:&quot; %%a in ( &#039;findstr /b &quot;::&quot; &quot;%~f0&quot;&#039; ) do echo:%%a
    goto :EOF
)

if &quot;%~1&quot; == &quot;&quot; (
    path
    goto :EOF
)

if /i &quot;%~1&quot; == &quot;path&quot; (
    path ;
    goto :EOF
)

setlocal

set &quot;unpath_subdir=&quot;
for %%a in ( %* ) do call :unpath_arg &quot;%%~a&quot;

if defined PATH set &quot;PATH=%PATH:~1%&quot;

endlocal &amp; set &quot;PATH=%PATH%&quot;
goto :EOF


:unpath_arg
if &quot;%~1&quot; == &quot;&quot; goto :EOF

if /i &quot;%~1&quot; == &quot;/S&quot; (
    set &quot;unpath_subdir=1&quot;
    goto :EOF
)

if /i &quot;%~1&quot; == &quot;/L&quot; (
    set &quot;unpath_subdir=&quot;
    goto :EOF
)

for /f &quot;tokens=*&quot; %%s in ( &quot;%PATH:;=&quot; &quot;%&quot; ) do (
    set &quot;PATH=&quot;
    for %%p in ( &quot;%%s&quot; ) do call :unpath_entry &quot;%%~p&quot; &quot;%~1&quot;
)
goto :EOF


:unpath_entry
if &quot;%~1&quot; == &quot;&quot; goto :EOF
if /i &quot;%~1&quot; == &quot;%~2&quot; goto :EOF

set &quot;unpath_entry=%~1&quot;
call set &quot;unpath_entry=%%unpath_entry:%~2=%%&quot;

if /i &quot;%~1&quot; == &quot;%~2%unpath_entry%&quot; if &quot;%unpath_entry:~0,1%.&quot; == &quot;\.&quot; if defined unpath_subdir goto :EOF

set &quot;PATH=%PATH%;%~1&quot;
goto :EOF

</code></pre></div><p>Оригинал на <a href="http://code.google.com/p/cmd-bat/source/browse/trunk/unpath.bat">google.code</a></p>]]></description>
			<author><![CDATA[null@example.com (Rumata)]]></author>
			<pubDate>Fri, 07 Feb 2014 20:20:43 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=79847#p79847</guid>
		</item>
	</channel>
</rss>
