What is this batch file doing (to make color text)?
Posted: 16 May 2024 09:26
Hello, sometimes I want to block internet access to some programs and I use for that this batch file:
https://github.com/charlesdh/addfwrs
It uses some batch file tricks that I don't understand to create colorful texts.
But there is some problem with this method when in current directory exist file or directory with same name as color text it tries to create.
File would be deleted and if there is directory it ends with "Access is denied."
This is that part I don't understand:
I run that as test.bat and text "Green" was written in green color and then I made directory called "Green" and with second run I got "Access is denied."
I have only basic understanding of batch files and can't figure out what those "%~2" or "<nul set ..." things do.
https://github.com/charlesdh/addfwrs
It uses some batch file tricks that I don't understand to create colorful texts.
But there is some problem with this method when in current directory exist file or directory with same name as color text it tries to create.
File would be deleted and if there is directory it ends with "Access is denied."
This is that part I don't understand:
Code: Select all
@echo off
echo Test
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
set "DEL=%%a"
)
call :ColorText 0a "Green"
goto :eof
:ColorText
echo off
<nul set /p ".=%DEL%" > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1
goto :eof
I have only basic understanding of batch files and can't figure out what those "%~2" or "<nul set ..." things do.