@Echo off
REM ''
REM '-------------------------------------------------------------------------'
REM ' #Script Description......: Lists Dirs contained in Path Valiable
REM ' #New.....................: 23.09.2025 / J.Fes'
REM ' #LUp.....................: 29.09.2025 / J.Fes'
REM ' #LUp.....................: 10.10.2025 / J.Fes use :PrintHeader'
REM ' #LUp.....................: 10.10.2025 / J.Fes add if p1 is set then use p1 as path
REM '-------------------------------------------------------------------------'

setlocal
 if not defined JobMgr_EchoLog_DPNE set JobMgr_EchoLog_DPNE=.

 Call %~dp0SetEnvFirstFound.cmd Echo2 "%ProgramData%\JobManager_V3\03-BinPublic\Echo2.cmd" "%ProgramData%\PLMPerfV4\03-BinPublic\Echo2.cmd" "%Echo2%.cmd"

 if "%~1" equ "" set PathForPrint=%Path%
 if "%~1" equ "" set PathInfoTxt=EnvVar:'Path'
 if "%~1" neq "" set PathForPrint=%~1
 if "%~1" neq "" set PathInfoTxt=Value:'%PathForPrint:~0,5%....%PathForPrint:~-5%'

 Call :PrintHeader
 rem Use FOR loop to split and print each path on a new line
 for %%i in ("%PathForPrint:;=" "%") do Call :PathEleCount "%%~i"
 for %%i in ("%PathForPrint:;=" "%") do Call :PathEleEcho "%%~i"
endlocal
goto :eof


:PathEleEcho
 if "%~1" equ "" goto :MyEnd
 set PathEle_DP=%~1
 set PathEle_DP_exist=NO
 if exist "%PathEle_DP%" set PathEle_DP_exist=YES
 set /a PathEle_c=%PathEle_c%+1
REM  Echo #D39
 set PathEle_p=0%PathEle_c%
REM  Echo #D41
 set PathEle_p=%PathEle_p:~-2%
REM  Echo #D43 %PathEle_DP%
 call %Echo2% "Path.Elem: (%PathEle_p%/%PathEle_n%) (Exist:%PathEle_DP_exist%)" "%PathEle_DP%"
 :MyEnd
 goto :eof

:PathEleCount
 if "%~1" equ "" goto :MyEnd
 set /a PathEle_n=%PathEle_n%+1
 :MyEnd
goto :eof

:PrintHeader
 Call %Echo2% "****"
 Call %Echo2% "*" "List Dirs contained in %PathInfoTxt% V:12.11.2025"
 Call %Echo2% "****"
goto :eof

:MyEnd

