@echo off
setlocal enabledelayedexpansion

:: Define the path you want to add
set "newPath=C:\instantclient"

:: Check if the path already exists in the PATH variable
echo !PATH! | findstr /i /c:";%newPath%;" > nul
if errorlevel 1 (
  :: If the path doesn't exist, add it to the PATH variable
  set newPath=!PATH!;%newPath%
  :: Check the length of the new PATH
  set "pathLength=0"
  for %%i in (!newPath!) do (
    set /a "pathLength+=1"
    set "pathElement=%%i"
  )
  
  :: If the new PATH exceeds the length limit, inform the user
  if !pathLength! gtr 1024 (
    echo Error: The new PATH exceeds the 1024 character limit.
    echo PATH not updated.
  ) else (
    :: Otherwise, update the system environment variable
    setx PATH "!newPath!" /M
    echo Path updated successfully.
  )
) else (
  echo Path already exists in the system environment variables.
)

endlocal

@echo off
setlocal
:: Define the name and value of the new environment variable
set "varName=OCI_LIB64"
set "varValue=C:\instantclient"

:: Add the new environment variable using setx
setx %varName% "%varValue%"

:: Display a message indicating success
echo %varName% has been set to %varValue%.

endlocal