github.com/ActiveState/cli@v0.0.0-20240508170324-6801f60cd051/internal/assets/contents/scripts/removePaths.bat (about)

     1  REM This script is used by 'state clean' on Windows as we cannot
     2  REM remove files that are currently in use. 
     3  REM In the case the State Tool, the binary cannot be removed while it is running.
     4  REM In the case of the config directory this is the log file, which 
     5  REM remains open and inaccessable while the State Tool is running.
     6  REM The expected arguments are the process ID, the executable name
     7  REM and a list of paths to be removed when the process has completed
     8  
     9  set logfile=%1
    10  shift
    11  set pid=%1
    12  shift
    13  set exe=%1
    14  shift
    15  
    16  set paths=
    17  :set_paths
    18      if not "%1"=="" (
    19          set paths=%paths% %1
    20          shift
    21          goto set_paths
    22      )
    23  
    24  for /f %%i in ('tasklist /NH /FI "PID eq %pid%"') do set proc=%%i
    25  echo "Waiting for process %exe% with PID %pid% to end..." >> %logfile%
    26  :wait_for_exit
    27      if %proc% == %exe% (
    28          for /f %%i in ('tasklist /NH /FI "PID eq %pid%"') do set proc=%%i
    29          goto :wait_for_exit
    30      )
    31  
    32  echo "Process %exe% has ended" >> %logfile%
    33  set success=true
    34  for %%i in (%paths%) do (
    35      echo "Attempting to remove path %%i" >> %logfile%
    36      if exist "%%i\" (
    37          rmdir /s /q %%i 2>>&1 >> %logfile%
    38      ) else if exist "%%i" (
    39          del /f /q %%i 2>>&1 >> %logfile%
    40      )
    41      if exist "%%i" (
    42          echo "Could not remove path: %%i" >> %logfile%
    43          set success=false
    44      ) else (
    45          echo "Successfully removed path %%i" >> %logfile%
    46      )
    47  )
    48  
    49  if "%success%"=="true" (
    50      echo "Successfully removed State Tool installation and related files." >> %logfile%
    51  ) else (
    52      echo "Failed to remove one or more State Tool files." >>  %logfile%
    53  )