PC Review


Reply
Thread Tools Rate Thread

Check if a a path is in PATH

 
 
BigMan
Guest
Posts: n/a
 
      12th Feb 2005
How should I check if a path is in the PATH environment variable?


 
Reply With Quote
 
 
 
 
Jerold Schulman
Guest
Posts: n/a
 
      12th Feb 2005
On Sat, 12 Feb 2005 11:26:34 +0200, "BigMan" <(E-Mail Removed)> wrote:

>How should I check if a path is in the PATH environment variable?
>


See tip 4263 in the 'Tips & Tricks' at http://www.jsiinc.com

Jerold Schulman
Windows Server MVP
JSI, Inc.
http://www.jsiinc.com
 
Reply With Quote
 
Matthias Tacke
Guest
Posts: n/a
 
      12th Feb 2005
BigMan wrote:
> How should I check if a path is in the PATH environment variable?
>

To first check and then append a path given as argument.

::Add2Path.bat:::::::::::::::::::::::::::::::::::::::::::::::::::::::::
@echo off
echo.%path%|find /C /I "%1">NUL
if errorlevel 1 set Path=%Path%;%1
::Add2Path.bat:::::::::::::::::::::::::::::::::::::::::::::::::::::::::

Or from commandline:
@echo.%path%|find /C /I "c:\newpath" >NUL ||set path=%path%;c:\newpath

HTH

--
Gruesse Greetings Saludos Saluti Salutations
Matthias
---------+---------+---------+---------+---------+---------+---------+
 
Reply With Quote
 
Stefan Kanthak
Guest
Posts: n/a
 
      13th Feb 2005
"Matthias Tacke" <(E-Mail Removed)> wrote:

> BigMan wrote:
> > How should I check if a path is in the PATH environment variable?
> >

> To first check and then append a path given as argument.
>
> ::Add2Path.bat:::::::::::::::::::::::::::::::::::::::::::::::::::::::::
> @echo off
> echo.%path%|find /C /I "%1">NUL


That's to silly?! The following is correct, but too clumsy for me:

echo.^;%path%^;|find /C /I ";%1;">NUL

So: Why not use

For %! In (%PATH%) Do If "%!" == "%1" Set ...

> if errorlevel 1 set Path=%Path%;%1
> ::Add2Path.bat:::::::::::::::::::::::::::::::::::::::::::::::::::::::::


Stefan
[
--
Die unaufgeforderte Zusendung einer Werbemail an Privatleute verstoesst gegen
§1 UWG und §823 I BGB. Beschluss des LG Berlin vom 2.4.1998 (AZ: 16 O 201/98)
Das unverlangte Versenden von Werbemail ist nach §1 UWG wettbewerbswidrig.
Beschluss des LG Traunstein vom 18.12.1997 (AZ: 2 HKO 3755/97)


 
Reply With Quote
 
BigMan
Guest
Posts: n/a
 
      13th Feb 2005
> So: Why not use
>
> For %! In (%PATH%) Do If "%!" == "%1" Set ...
>

I think this does not work...


 
Reply With Quote
 
Matthias Tacke
Guest
Posts: n/a
 
      13th Feb 2005
BigMan wrote:
>>So: Why not use
>>
>>For %! In (%PATH%) Do If "%!" == "%1" Set ...
>>

> I think this does not work...


It does work, except for paths containing spaces.

--
Gruesse Greetings Saludos Saluti Salutations
Matthias
---------+---------+---------+---------+---------+---------+---------+
 
Reply With Quote
 
BigMan
Guest
Posts: n/a
 
      13th Feb 2005
OK, please give the source of a bat file that writes every path in PATH to
the screen...


 
Reply With Quote
 
Matthias Tacke
Guest
Posts: n/a
 
      13th Feb 2005
BigMan wrote:
> OK, please give the source of a bat file that writes every path in PATH to
> the screen...
>
>

commandline:
for %A in ("%path:;=";"%") do @echo %~A

Batch:
for %%A in ("%path:;=";"%") do @echo %%~A

--
Gruesse Greetings Saludos Saluti Salutations
Matthias
---------+---------+---------+---------+---------+---------+---------+
 
Reply With Quote
 
BigMan
Guest
Posts: n/a
 
      14th Feb 2005
Wow!
Could you explain this: "%path:;=";"%"


 
Reply With Quote
 
Matthias Tacke
Guest
Posts: n/a
 
      14th Feb 2005
BigMan wrote:
> Wow!
> Could you explain this: "%path:;=";"%"
>
>

The standard for has the space "," and the ";" as standard delmiters.
(at least - may be locale dependant)
If there are spaces in any of the folders in the path, for will
break at that point. To avoid this I quote every single path by
replacing all simicolons with quote semicolon quote plus quotes
at the begin and end resulting in proper parsed output.

See:
for /?
set /?
for details on handling environment vars.

--
Gruesse Greetings Saludos Saluti Salutations
Matthias
---------+---------+---------+---------+---------+---------+---------+
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to judge whether a path is relative path or absolute path thinktwice Microsoft Windows 2000 CMD Promt 20 7th May 2008 11:06 PM
set path, change path - path grayed out John Smith Windows XP Help 1 12th Feb 2005 01:56 PM
set path, change path - path grayed out John Smith Windows XP General 1 12th Feb 2005 01:56 PM
The specified path does not exist, check path then try again? =?Utf-8?B?VGhlIHNwZWNpZmllZCBwYXRoIGRvZXMgbm90IGV4 Windows XP General 3 7th Jan 2004 03:35 AM
"The specified path does not exist. Check the path, and then try again." Windows XP General 3 23rd Dec 2003 12:04 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:31 AM.