1
1
@ echo off
2
2
3
-
4
3
call " %~dp0 lib_base.cmd"
5
4
call " %% ~dp0lib_console"
6
5
set lib_path = call " %~dp0 lib_path.cmd"
@@ -11,6 +10,13 @@ if "%~1" == "/h" (
11
10
call :%*
12
11
)
13
12
13
+ setlocal enabledelayedexpansion
14
+ if not defined find_pathext (
15
+ set " find_pathext = !PATHEXT:; = ! "
16
+ set " find_pathext = !find_pathext:. =\. ! "
17
+ )
18
+ endlocal & set " find_pathext = %find_pathext% "
19
+
14
20
exit /b
15
21
16
22
:enhance_path
@@ -32,13 +38,12 @@ exit /b
32
38
:: :options:
33
39
:: :
34
40
:: : append <in> Append to the path env variable rather than pre-pend.
35
- :: B
41
+ :: :
36
42
:: :
37
43
:: :output:
38
44
:: :
39
45
:: : path <out> Sets the path env variable if required.
40
46
:: :-------------------------------------------------------------------------------
41
-
42
47
if " %~1 " neq " " (
43
48
set " add_path = %~1 "
44
49
) else (
@@ -52,7 +57,8 @@ exit /b
52
57
set " position = "
53
58
)
54
59
55
- dir " %add_path% " | findstr -i " \.COM \.EXE \.BAT \.CMD \.PS1 \.VBS" > NUL
60
+ dir " %add_path% " 2 > NUL | findstr -i -e " %find_pathext% " > NUL
61
+
56
62
if " %ERRORLEVEL% " == " 0" (
57
63
set " add_to_path = %add_path% "
58
64
) else (
@@ -81,20 +87,20 @@ exit /b
81
87
echo " !path! " | !WINDIR! \System32\findstr > nul /I /R /C:" ;!find_query! ;"
82
88
call :set_found
83
89
)
84
- %print_debug% :enhance_path " Env Var INSIDE PATH !find_query! - found=!found! "
90
+ %print_debug% :enhance_path " Env Var INSIDE PATH !find_query! - found=!found! "
85
91
86
92
if /i " !position! " == " append" (
87
93
if " !found! " == " 0" (
88
94
echo " !path! " | !WINDIR! \System32\findstr > nul /I /R /C:" ;!find_query! \" $"
89
95
call :set_found
90
96
)
91
- %print_debug% :enhance_path " Env Var END PATH !find_query! - found=!found! "
97
+ %print_debug% :enhance_path " Env Var END PATH !find_query! - found=!found! "
92
98
) else (
93
99
if " !found! " == " 0" (
94
100
echo " !path! " | !WINDIR! \System32\findstr > nul /I /R /C:" ^\" !find_query! ;"
95
101
call :set_found
96
102
)
97
- %print_debug% :enhance_path " Env Var BEGIN PATH !find_query! - found=!found! "
103
+ %print_debug% :enhance_path " Env Var BEGIN PATH !find_query! - found=!found! "
98
104
)
99
105
endlocal & set found = %found%
100
106
@@ -129,13 +135,12 @@ exit /b
129
135
exit /b
130
136
131
137
:changed
132
- %print_debug% :enhance_path " END Env Var - PATH=%path% "
133
- %print_debug% :enhance_path " Env Var %find_query% - found=%found% "
138
+ %print_debug% :enhance_path " END Env Var - PATH=%path% "
139
+ %print_debug% :enhance_path " Env Var %find_query% - found=%found% "
134
140
exit /b
135
141
136
142
exit /b
137
143
138
-
139
144
:set_found
140
145
if " %ERRORLEVEL% " == " 0" (
141
146
set found = 1
@@ -190,7 +195,7 @@ exit /b
190
195
set " position = "
191
196
)
192
197
193
- dir " %add_path% " 2 > NUL | findstr -i " \.COM \.EXE \.BAT \.CMD \.PS1 \.VBS " > NUL
198
+ dir " %add_path% " 2 > NUL | findstr -i -e " %find_pathext% " > NUL
194
199
195
200
if " %ERRORLEVEL% " == " 0" (
196
201
set " add_to_path = %add_path% "
@@ -204,7 +209,7 @@ exit /b
204
209
set " path = %path% ;%add_to_path% "
205
210
) else (
206
211
set " path = %add_to_path% ;%path% "
207
- )
212
+ )
208
213
)
209
214
)
210
215
@@ -213,10 +218,10 @@ exit /b
213
218
exit /b
214
219
)
215
220
216
- %print_debug% :set_path_recursive " Env Var - add_path=%add_to_path% "
217
- %print_debug% :set_path_recursive " Env Var - position=%position% "
218
- %print_debug% :set_path_recursive " Env Var - depth=%depth% "
219
- %print_debug% :set_path_recursive " Env Var - max_depth=%max_depth% "
221
+ %print_debug% :set_path_recursive " Env Var - add_path=%add_to_path% "
222
+ %print_debug% :set_path_recursive " Env Var - position=%position% "
223
+ %print_debug% :set_path_recursive " Env Var - depth=%depth% "
224
+ %print_debug% :set_path_recursive " Env Var - max_depth=%max_depth% "
220
225
221
226
if %max_depth% gtr %depth% (
222
227
if " %add_to_path% " neq " " (
@@ -225,7 +230,7 @@ exit /b
225
230
set " path = %path% ;%add_to_path% "
226
231
) else (
227
232
set " path = %add_to_path% ;%path% "
228
- )
233
+ )
229
234
)
230
235
call :set_depth
231
236
call :loop_depth
@@ -235,7 +240,7 @@ exit /b
235
240
236
241
exit /b
237
242
238
- : set_depth
243
+ :set_depth
239
244
set /a " depth = %depth% + 1"
240
245
exit /b
241
246
@@ -245,10 +250,16 @@ exit /b
245
250
)
246
251
247
252
for /d %%i in (" %add_path% \*" ) do (
253
+ <<<<<<< HEAD
248
254
%print_debug% :set_path_recursive " Env Var BEFORE - depth=%depth% "
249
255
%print_debug% :set_path_recursive " Found Subdirectory - '%%~fi '"
250
256
call :set_path_recursive " %%~fi " %depth% %max_depth% %position%
251
257
%print_debug% :set_path_recursive " Env Var AFTER- depth=%depth% "
258
+ ====== =
259
+ %print_debug% :enhance_path_recursive " Env Var BEFORE - depth=%depth% "
260
+ %print_debug% :enhance_path_recursive " Found Subdirectory - '%%~fi '"
261
+ call :enhance_path_recursive " %%~fi " %depth% %max_depth% %position%
262
+ %print_debug% :enhance_path_recursive " Env Var AFTER- depth=%depth% "
263
+ >>>>>>> 126347025f9cade241beff182738b2527da7535e
252
264
)
253
265
exit /b
254
-
0 commit comments