Skip to content

Instantly share code, notes, and snippets.

@dolmen
Created March 18, 2011 19:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dolmen/876725 to your computer and use it in GitHub Desktop.
Save dolmen/876725 to your computer and use it in GitHub Desktop.
A procedure that call a callback for each directory of %PATH%
@echo off
:: Copyright © 2011 Olivier Mengué
:: License GNU GPL 3.0
setlocal
call :VisitPATH :Echo
goto :EOF
:Echo
echo.[%~1]
echo %PATH%
goto :EOF
:: VisitPATH
::
:: %1 callback name
::
: == VisitPATH ==
:: Save PATH
set VisitPATH_P=%PATH%
call :VisitPATH_Loop %1 .
goto :EOF
:VisitPATH_Loop
set VisitPATH_Q=%PATH%
:: Find the first "." in the reduced %PATH% => first directory in %PATH%
set PATH=%VisitPATH_P%& call %1 "%~$PATH:2"
set PATH=%VisitPATH_Q:*;=%
if not "%PATH%"=="%VisitPATH_Q%" goto :VisitPATH_Loop
set PATH=%VisitPATH_P%
set VisitPATH_P=
set VisitPATH_Q=
goto :EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment