Repository navigation
Expand file tree
/
Copy pathinstall.bat
More file actions
76 lines (64 loc) · 2.37 KB
/
Copy pathinstall.bat
File metadata and controls
76 lines (64 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
@echo off
setlocal enabledelayedexpansion
echo ====================================================
echo Codez PATH Installer / Updater
echo ====================================================
echo.
:: Ensure the script is running with administrative privileges
net session >nul 2>&1
if %errorlevel% neq 0 (
echo [ERROR] This script must be executed as an Administrator.
echo Please right-click this file and select 'Run as administrator'.
echo.
pause
exit /b
)
:: Get the directory where this batch file is currently located
set "CURRENT_DIR=%~dp0"
:: Remove the trailing backslash for consistency
if "%CURRENT_DIR:~-1%"=="\" set "CURRENT_DIR=%CURRENT_DIR:~0,-1%"
echo [INFO] Target folder to add: "%CURRENT_DIR%"
:: Fetch the current USER PATH from the registry
for /f "tokens=2*" %%A in ('reg query "HKCU\Environment" /v PATH 2^>nul') do set "OLD_PATH=%%B"
:: Initialize the new path variable
set "NEW_PATH="
:: Split the old path by semicolons and rebuild it without any existing "codez" entries
for %%G in ("%OLD_PATH:;=" "%") do (
set "ENTRY=%%~G"
:: Strip trailing spaces if any
set "ENTRY=!ENTRY!"
:: Check if the path entry contains "codez" (case-insensitive)
echo !ENTRY! | findstr /i "codez" >nul
if errorlevel 1 (
:: If it doesn't contain "codez", keep it in the new path list
if not "!ENTRY!"=="" (
if "!NEW_PATH!"=="" (
set "NEW_PATH=!ENTRY!"
) else (
set "NEW_PATH=!NEW_PATH!;!ENTRY!"
)
)
) else (
echo [INFO] Removing old conflicting entry: "!ENTRY!"
)
)
:: Append the current directory to the clean path list
if "!NEW_PATH!"=="" (
set "FINAL_PATH=%CURRENT_DIR%"
) else (
set "FINAL_PATH=%NEW_PATH%;%CURRENT_DIR%"
)
:: Apply the updated PATH back to the User Registry environment
reg add "HKCU\Environment" /v PATH /t REG_EXPAND_SZ /d "%FINAL_PATH%" /f >nul
if %errorlevel% equ 0 (
echo.
echo [SUCCESS] "%CURRENT_DIR%" has been successfully added to your PATH.
echo [SUCCESS] Any old "codez" directory entries were overwritten.
echo.
echo *Note: Please restart any open terminal windows for the changes to take effect.*
) else (
echo.
echo [ERROR] Failed to update the PATH environment variable.
)
echo.
pause