Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off
- setlocal enableDelayedExpansion
- REM Initialize some maybe needed vars
- set "thisDir=%~dp0"
- REM Set path to file to kill
- set "killFile=%TEMP%\QBSearchIndexerError.txt"
- REM Set some default options
- REM 24 hours is 86400
- set /a timeWait=86400
- set /a messageTime=5
- set "showTime=true"
- set "toRename=false"
- set "toForce=true"
- set "randName="
- call :getKillName "%killFile%" killName
- call :getKillPath "%killFile%" killPath
- call :getKillNameExt "%killFile%" killNameExt
- call :getDateStringFromSeconds "%timeWait%" waitString
- :main
- cls
- echo ### ###
- echo # QuickDeath - by CorpNewt #
- echo ### ###
- echo.
- echo Waiting !waitString!...
- if /i "%showTime%"=="true" (
- timeout %timeWait%
- ) else (
- timeout %timeWait% > nul
- )
- goto quickKill
- :quickKill
- cls
- echo ### ###
- echo # QuickDeath - by CorpNewt #
- echo ### ###
- echo.
- REM Check if the file exists, and if not
- REM wait 5 seconds and return to the wait
- If NOT EXIST "%killFile%" (
- echo "%killNameExt%" does not exist at
- echo "%killPath%"
- echo.
- echo Returning to wait...
- timeout %messageTime% > nul
- goto main
- )
- echo Killing "%killFile%"
- echo.
- if /i "%toRename%"=="true" (
- call :getTempName "%killFile%" randName
- REM Rename file, then delete it
- echo Renaming "%killNameExt%" to "!randName!"...
- REM move to killPath, then rename
- pushd "%killPath%"
- ren "%killNameExt%" "!randName!"
- echo.
- echo Deleting "!randName!"...
- if /i "%toForce%"=="true" (
- del /f "!randName!"
- ) else (
- del "!randName!"
- )
- popd
- echo.
- ) else (
- echo Deleting "!killNameExt!"...
- pushd "%killPath%"
- del "%killNameExt%"
- if /i "%toForce%"=="true" (
- del /f "%killNameExt%"
- ) else (
- del "%killNameExt%"
- )
- popd
- echo.
- )
- echo Done.
- timeout %messageTime% > nul
- goto main
- REM ### ###
- REM # Helper Functions #
- REM ### ###
- :getKillName <input> <result>
- set "%~2=%~n1"
- goto :EOF
- :getKillNameExt <input> <result>
- set "%~2=%~nx1"
- goto :EOF
- :getKillPath <input> <result>
- set "%~2=%~dp1"
- goto :EOF
- :getTempName <input> <result>
- set "%~2=!RANDOM!-!RANDOM!-!RANDOM!-!RANDOM!%~x1"
- goto :EOF
- :getDateStringFromSeconds <seconds> <stringResult>
- set /a theTime=%~1
- set /a hours=0
- set /a minutes=0
- set /a seconds=0
- set "hourString="
- set "minuteString="
- set "secondString="
- REM Get the individual amounts
- set /a hours=%theTime%/3600
- set /a minutes=(%theTime%-(%hours% * 3600))/60
- set /a seconds=%theTime%-(%hours% * 3600)-(%minutes% * 60)
- REM Set each string
- if %hours% EQU 1 (
- set "hourString=%hours% hour"
- ) else if %hours% GTR 1 (
- set "hourString=%hours% hours"
- )
- if %minutes% GTR 0 (
- if %hours% GTR 0 (
- if /i NOT "%hourString:~-2%"==", " (
- set "hourString=%hourString%, "
- )
- )
- if %minutes% EQU 1 (
- set "minuteString=%minutes% minute"
- ) else if %minutes% GTR 1 (
- set "minuteString=%minutes% minutes"
- )
- )
- if %seconds% GTR 0 (
- if %hours% GTR 0 (
- if /i NOT "%hourString:~-2%"==", " (
- set "hourString=%hourString%, "
- )
- )
- if %minutes% GTR 0 (
- if /i NOT "%minuteString:~-2%"==", " (
- set "minuteString=%minuteString%, "
- )
- )
- if %seconds% EQU 1 (
- set "secondString=%seconds% second"
- ) else if %seconds% GTR 1 (
- set "secondString=%seconds% seconds"
- )
- )
- REM set the result
- set "%~2=%hourString%%minuteString%%secondString%"
- goto :EOF
- :padNonEmptyEnd <stringVarName>
- if "!%~1!"=="" goto :EOF
- set "%~1=!%~1!, "
- goto :EOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement