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
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | |
:Admin <Return> [Needed] [Success] | |
:: Check for Administrator privileges and request privileges if Needed 'true'. | |
:::: Usage: call :Admin xReturn true | |
:: Return success value, if user is Admin. Default `true` if Success not set. | |
setlocal | |
set "xVBUAC=%Temp%\AdminUAC.vbs" | |
set "xSuccess=true" | |
set "xAdmin=false" | |
if not "%~3"=="" set "xSuccess=%~3" |
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
@echo off | |
setlocal EnableDelayedExpansion | |
rem Loop through all of the drives to find the external HDD | |
for %%D in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do ( | |
for /f "tokens=5" %%S in ('vol %%~D:') do set "xSerial=%%S" | |
if "%xSerial%"=="ABCD-1234" ( | |
rem TODO Specify the exact target copy base location that you want. | |
set "xTarget=%%~D:\%ComputerName%" | |
) |
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 |
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 Commands | |
@echo off | |
:: Erase Existing Files | |
>match.txt ( <nul set /p "=" ) | |
>nomatch.txt ( <nul set /p "=" ) | |
:: Loop through Source and Generate Output | |
for /f "tokens=1,* delims=]" %%K in ('type temp.txt ^| find /V /N ""') do ( | |
for /f "delims=" %%X in ('echo(%%L ^| find /V "green"') do ( |
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
@echo off | |
set "Var=2210 2215 2211 22106 22109 221" | |
:: Set Unique EOL Identifier, Loop through list, remove last item, and save. | |
:: The EOL Identifier should be a sequence or character that is not allowed in the variable normally. | |
:: This must be determined at the time of usage by the programmer. | |
set "Var=%Var%@" | |
for /f "delims=" %%A in ('echo(%Var: =^&echo(%') do call set "Var2=%%Var: %%A=%%" | |
set "Var=%Var2%" |
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
@echo off | |
setlocal EnableExtensions DisableDelayedExpansion | |
for /F "delims=" %%Z in ('type file.txt') do ( | |
set "xLine=|%%Z" | |
call :Parse xLine | |
) | |
endlocal | |
pause >nul | |
goto :eof |
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
:: Without Delayed Expansion | |
@echo off | |
setlocal EnableExtensions DisableDelayedExpansion | |
for /f delims^=^ eol^= %%L in (myfile.txt) do ( | |
set "xLine=%%L" | |
call set "xLine=%%xLine:"=%%" %= Fix for Limitation 2 =% | |
rem Remove the .0x08 when wanting to output the text to a file. | |
2>nul ( <nul set /p =".%%L" ) %= Fixed Limitation 1, 3, and 4 =% | |
call :NewLine | |
) |
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
@echo off | |
setlocal EnableExtensions DisableDelayedExpansion | |
:: Limitations | |
:: 1. Any leading close bracket ] characters will be trimmed due to the delims=] | |
:: 2. The text being replaced (search term) may not contain any equal signs = | |
for /r %%F in (html.txt) do if exist "%%~fF" ( | |
for /f "tokens=1,* delims=]" %%K in ('type "%%~fF" ^| find /n /v ""') do ( | |
set "_=%%L" |