Advertisement
corpnewt

QuickDeath.bat

Apr 29th, 2016
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.48 KB | None | 0 0
  1. @echo off
  2. setlocal enableDelayedExpansion
  3.  
  4. REM Initialize some maybe needed vars
  5. set "thisDir=%~dp0"
  6. REM Set path to file to kill
  7. set "killFile=%TEMP%\QBSearchIndexerError.txt"
  8.  
  9. REM Set some default options
  10. REM 24 hours is 86400
  11. set /a timeWait=86400
  12. set /a messageTime=5
  13. set "showTime=true"
  14. set "toRename=false"
  15. set "toForce=true"
  16. set "randName="
  17.  
  18. call :getKillName "%killFile%" killName
  19. call :getKillPath "%killFile%" killPath
  20. call :getKillNameExt "%killFile%" killNameExt
  21. call :getDateStringFromSeconds "%timeWait%" waitString
  22.  
  23. :main
  24. cls
  25. echo ### ###
  26. echo # QuickDeath - by CorpNewt #
  27. echo ### ###
  28. echo.
  29. echo Waiting !waitString!...
  30. if /i "%showTime%"=="true" (
  31. timeout %timeWait%
  32. ) else (
  33. timeout %timeWait% > nul
  34. )
  35. goto quickKill
  36.  
  37. :quickKill
  38. cls
  39. echo ### ###
  40. echo # QuickDeath - by CorpNewt #
  41. echo ### ###
  42. echo.
  43. REM Check if the file exists, and if not
  44. REM wait 5 seconds and return to the wait
  45. If NOT EXIST "%killFile%" (
  46. echo "%killNameExt%" does not exist at
  47. echo "%killPath%"
  48. echo.
  49. echo Returning to wait...
  50. timeout %messageTime% > nul
  51. goto main
  52. )
  53.  
  54. echo Killing "%killFile%"
  55. echo.
  56. if /i "%toRename%"=="true" (
  57. call :getTempName "%killFile%" randName
  58. REM Rename file, then delete it
  59. echo Renaming "%killNameExt%" to "!randName!"...
  60.  
  61. REM move to killPath, then rename
  62. pushd "%killPath%"
  63. ren "%killNameExt%" "!randName!"
  64. echo.
  65. echo Deleting "!randName!"...
  66. if /i "%toForce%"=="true" (
  67. del /f "!randName!"
  68. ) else (
  69. del "!randName!"
  70. )
  71. popd
  72. echo.
  73. ) else (
  74. echo Deleting "!killNameExt!"...
  75. pushd "%killPath%"
  76. del "%killNameExt%"
  77. if /i "%toForce%"=="true" (
  78. del /f "%killNameExt%"
  79. ) else (
  80. del "%killNameExt%"
  81. )
  82. popd
  83. echo.
  84. )
  85. echo Done.
  86. timeout %messageTime% > nul
  87. goto main
  88.  
  89. REM ### ###
  90. REM # Helper Functions #
  91. REM ### ###
  92.  
  93. :getKillName <input> <result>
  94. set "%~2=%~n1"
  95. goto :EOF
  96. :getKillNameExt <input> <result>
  97. set "%~2=%~nx1"
  98. goto :EOF
  99. :getKillPath <input> <result>
  100. set "%~2=%~dp1"
  101. goto :EOF
  102. :getTempName <input> <result>
  103. set "%~2=!RANDOM!-!RANDOM!-!RANDOM!-!RANDOM!%~x1"
  104. goto :EOF
  105. :getDateStringFromSeconds <seconds> <stringResult>
  106. set /a theTime=%~1
  107. set /a hours=0
  108. set /a minutes=0
  109. set /a seconds=0
  110. set "hourString="
  111. set "minuteString="
  112. set "secondString="
  113.  
  114. REM Get the individual amounts
  115. set /a hours=%theTime%/3600
  116. set /a minutes=(%theTime%-(%hours% * 3600))/60
  117. set /a seconds=%theTime%-(%hours% * 3600)-(%minutes% * 60)
  118.  
  119. REM Set each string
  120. if %hours% EQU 1 (
  121. set "hourString=%hours% hour"
  122. ) else if %hours% GTR 1 (
  123. set "hourString=%hours% hours"
  124. )
  125. if %minutes% GTR 0 (
  126. if %hours% GTR 0 (
  127. if /i NOT "%hourString:~-2%"==", " (
  128. set "hourString=%hourString%, "
  129. )
  130. )
  131. if %minutes% EQU 1 (
  132. set "minuteString=%minutes% minute"
  133. ) else if %minutes% GTR 1 (
  134. set "minuteString=%minutes% minutes"
  135. )
  136. )
  137. if %seconds% GTR 0 (
  138. if %hours% GTR 0 (
  139. if /i NOT "%hourString:~-2%"==", " (
  140. set "hourString=%hourString%, "
  141. )
  142. )
  143. if %minutes% GTR 0 (
  144. if /i NOT "%minuteString:~-2%"==", " (
  145. set "minuteString=%minuteString%, "
  146. )
  147. )
  148. if %seconds% EQU 1 (
  149. set "secondString=%seconds% second"
  150. ) else if %seconds% GTR 1 (
  151. set "secondString=%seconds% seconds"
  152. )
  153. )
  154.  
  155. REM set the result
  156. set "%~2=%hourString%%minuteString%%secondString%"
  157. goto :EOF
  158.  
  159. :padNonEmptyEnd <stringVarName>
  160. if "!%~1!"=="" goto :EOF
  161. set "%~1=!%~1!, "
  162. goto :EOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement