This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:: Batch Code Line Debugging | |
:: Retrieve the batch file line number where the Line function is called. | |
:: by David Ruhmann | |
:: Hide Command and Isolate Scope | |
@echo off | |
setlocal | |
:: Usage Example | |
call :False xResult |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:: Parse Example | |
:: Set a variable for each parameter flag to the value. flag:value, xflag=value | |
:: by David Ruhmann | |
:: Hide Commands | |
@echo off | |
:: Initilize Example | |
set "xParams=%*" | |
echo.%* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | |
:Log <xLog> <xMessage> [xParrot] [xSession] | |
:: Append the message with a timestamp out to the specified log file and repeat | |
:: the message to the display if xParrot is set to 1. | |
if not "%~1"=="" if exist "%~1" echo.%Date% %Time% %~4: %~2 >> "%~1" | |
if /i "%~3"=="1" echo.%~2 | |
goto :eof | |
:: by David Ruhmann |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | |
:IsDecimal <xReturn> <xInput> [xDelims] | |
:: Return true if the input is a decimal 10.0 number, else return false. | |
:::: Only allows for period seperator unless specified by xDelims. ,[tab][space] | |
call :IsNumber %1 %2 %3 | |
goto :eof | |
:: by David Ruhmann |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:: Determine if a Variable name is defined with a value. | |
:: by David Ruhmann | |
:: Hide Commands | |
@echo off | |
setlocal ENABLEEXTENSIONS | |
:: Example Usage | |
set "xVar=Value" | |
call :IsDefined xResult xVar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:: Hide Command | |
@echo off | |
set "xResult=" | |
::if exist "Output.xml" del /f /q "Output.xml" | |
call :ReplaceWith xResult "Source.xml" "<Tools>" "Input.xml" "Output.xml" | |
echo.%xResult% | |
goto End |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
setlocal | |
set "myString=abcdef!%%^^()^!" | |
call :strlen result myString | |
echo %result% | |
goto :eof | |
:strlen <resultVar> <stringVar> | |
( | |
setlocal EnableDelayedExpansion | |
set "s=!%~2!#" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:: Output a single character. | |
:: Does not work with whitespace on versions of Windows | |
:: after XP which trim leading whitespace. | |
>File.txt ( <nul set /p "= " ) | |
:: Output 0x0C New Page | |
cls>File.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:: Create an empty temp directory and purge all files and folders in the current directory that are younger than 5 days old. | |
:: See RoboCopy /? for all of the available options like /E for recursive. Remove /L to actually perform the deletions. | |
RD /S /Q "%Temp%\Temp" 2>nul & MKDIR "%Temp%\Temp" && ROBOCOPY "%Temp%\Temp" "C:\Backup" /PURGE /MT /MAXAGE:5 /NS /NC /NJH /NJS /L |