This commit is contained in:
David Refoua
2024-11-14 00:08:31 +03:30
3 changed files with 39 additions and 26 deletions

View File

@ -1,6 +1,5 @@
@echo off
call "%~dp0lib_base.cmd"
call "%%~dp0lib_console"
set lib_path=call "%~dp0lib_path.cmd"
@ -11,6 +10,13 @@ if "%~1" == "/h" (
call :%*
)
setlocal enabledelayedexpansion
if not defined find_pathext (
set "find_pathext=!PATHEXT:;= !"
set "find_pathext=!find_pathext:.=\.!"
)
endlocal & set "find_pathext=%find_pathext%"
exit /b
:enhance_path
@ -32,13 +38,12 @@ exit /b
:::options:
:::
::: append <in> Append to the path env variable rather than pre-pend.
::B
:::
:::
:::output:
:::
::: path <out> Sets the path env variable if required.
:::-------------------------------------------------------------------------------
if "%~1" neq "" (
set "add_path=%~1"
) else (
@ -52,7 +57,8 @@ exit /b
set "position="
)
dir "%add_path%" | findstr -i "\.COM \.EXE \.BAT \.CMD \.PS1 \.VBS" >NUL
dir "%add_path%" 2>NUL | findstr -i -e "%find_pathext%" >NUL
if "%ERRORLEVEL%" == "0" (
set "add_to_path=%add_path%"
) else (
@ -81,20 +87,20 @@ exit /b
echo "!path!"|!WINDIR!\System32\findstr >nul /I /R /C:";!find_query!;"
call :set_found
)
%print_debug% :enhance_path "Env Var INSIDE PATH !find_query! - found=!found!"
%print_debug% :enhance_path "Env Var INSIDE PATH !find_query! - found=!found!"
if /i "!position!" == "append" (
if "!found!" == "0" (
echo "!path!"|!WINDIR!\System32\findstr >nul /I /R /C:";!find_query!\"$"
call :set_found
)
%print_debug% :enhance_path "Env Var END PATH !find_query! - found=!found!"
%print_debug% :enhance_path "Env Var END PATH !find_query! - found=!found!"
) else (
if "!found!" == "0" (
echo "!path!"|!WINDIR!\System32\findstr >nul /I /R /C:"^\"!find_query!;"
call :set_found
)
%print_debug% :enhance_path "Env Var BEGIN PATH !find_query! - found=!found!"
%print_debug% :enhance_path "Env Var BEGIN PATH !find_query! - found=!found!"
)
endlocal & set found=%found%
@ -129,13 +135,12 @@ exit /b
exit /b
:changed
%print_debug% :enhance_path "END Env Var - PATH=%path%"
%print_debug% :enhance_path "Env Var %find_query% - found=%found%"
%print_debug% :enhance_path "END Env Var - PATH=%path%"
%print_debug% :enhance_path "Env Var %find_query% - found=%found%"
exit /b
exit /b
:set_found
if "%ERRORLEVEL%" == "0" (
set found=1
@ -190,7 +195,7 @@ exit /b
set "position="
)
dir "%add_path%" 2>NUL | findstr -i "\.COM \.EXE \.BAT \.CMD \.PS1 \.VBS" >NUL
dir "%add_path%" 2>NUL | findstr -i -e "%find_pathext%" >NUL
if "%ERRORLEVEL%" == "0" (
set "add_to_path=%add_path%"
@ -204,7 +209,7 @@ exit /b
set "path=%path%;%add_to_path%"
) else (
set "path=%add_to_path%;%path%"
)
)
)
)
@ -213,10 +218,10 @@ exit /b
exit /b
)
%print_debug% :set_path_recursive "Env Var - add_path=%add_to_path%"
%print_debug% :set_path_recursive "Env Var - position=%position%"
%print_debug% :set_path_recursive "Env Var - depth=%depth%"
%print_debug% :set_path_recursive "Env Var - max_depth=%max_depth%"
%print_debug% :set_path_recursive "Env Var - add_path=%add_to_path%"
%print_debug% :set_path_recursive "Env Var - position=%position%"
%print_debug% :set_path_recursive "Env Var - depth=%depth%"
%print_debug% :set_path_recursive "Env Var - max_depth=%max_depth%"
if %max_depth% gtr %depth% (
if "%add_to_path%" neq "" (
@ -225,7 +230,7 @@ exit /b
set "path=%path%;%add_to_path%"
) else (
set "path=%add_to_path%;%path%"
)
)
)
call :set_depth
call :loop_depth
@ -235,7 +240,7 @@ exit /b
exit /b
: set_depth
:set_depth
set /a "depth=%depth%+1"
exit /b
@ -245,10 +250,16 @@ exit /b
)
for /d %%i in ("%add_path%\*") do (
<<<<<<< HEAD
%print_debug% :set_path_recursive "Env Var BEFORE - depth=%depth%"
%print_debug% :set_path_recursive "Found Subdirectory - '%%~fi'"
call :set_path_recursive "%%~fi" %depth% %max_depth% %position%
%print_debug% :set_path_recursive "Env Var AFTER- depth=%depth%"
=======
%print_debug% :enhance_path_recursive "Env Var BEFORE - depth=%depth%"
%print_debug% :enhance_path_recursive "Found Subdirectory - '%%~fi'"
call :enhance_path_recursive "%%~fi" %depth% %max_depth% %position%
%print_debug% :enhance_path_recursive "Env Var AFTER- depth=%depth%"
>>>>>>> 126347025f9cade241beff182738b2527da7535e
)
exit /b