title: How to check if a directory exists in %PATH%
body: <p>How does one check if a directory is already present in the PATH environment variable? Here's a start. All I've managed to do with the code below, though, is echo the first directory in %PATH%. Since this is a FOR loop you'd think it would enumerate all the directories in %PATH%, but it only gets the first one.</p>
  <p>Is there a better way of doing this? Something like <a href="https://ss64.com/nt/find.html" rel="nofollow noreferrer">FIND</a> or <a href="https://ss64.com/nt/findstr.html" rel="nofollow noreferrer">FINDSTR</a> operating on the %PATH% variable? I'd just like to check if a directory exists in the list of directories in %PATH%, to avoid adding something that might already be there.</p>
  <pre><code>FOR /F &quot;delims=;&quot; %%P IN (&quot;%PATH%&quot;) DO (
      @ECHO %%~P
  )
  </code></pre>