How do I make those two codes work in one code? - batch-file

I'm working for days to get code for coloring text,
I get this one which work perfectly:
#Echo Off
SETLOCAL EnableDelayedExpansion
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
set "DEL=%%a"
)
call :colorEcho 0a "This is colored green with a black background!"
echo.
call :colorEcho a0 "This is colored black with a green background!"
echo.
pause
exit
:colorEcho
echo off
<nul set /p ".=%DEL%" > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1i
But I don't know how to get it work with mine:
For /f "tokens=1-3 delims=/ " %%a in ('date /t') do (
set mydate=%%c%%b%%a
set myyear=%%c
set mymonth=%%b
)
mkdir "C:\TEST\%myyear%\%mymonth%\%mydate%\"
for /d %%X in (*) do "C:\Program Files\WinRAR\WinRAR.exe" a -u -r -ed -m5 -agYYYYMMDD "C:\TEST\%myyear%\%mymonth%\%mydate%\Test_%%X_.rar" "C:\DATA\%%X\*.*"
How do I make a variable %%X (Which is a folder to zip) in my code colored?
Thanks

Related

Output in a file a variable in batch

I would like to input a variable to a text file in batch. I've tried a couple of things but I can't seem to find the proper variable. Can anybody help?
Here's my code:
echo.
echo List of all recorded wifi networks and their passwords:
echo.
setlocal enabledelayedexpansion
for /f "tokens=2delims=:" %%a in ('netsh wlan show profile ^|findstr ":"') do (
set "ssid=%%~a"
call :getpwd "%%ssid:~1%%"
)
echo.
echo.
choice /M "Do you want to save results to a txt file?"
set path=%errorlevel%
if %path% EQU 1 goto save_to_txt
if %path% EQU 2 goto END
:save_to_txt
if not exist List.txt (
echo Output of Wifi password grabber.bat > List.txt
)
echo ssid: %ssid% pass: %%i>> List.txt
pause
exit /b
:END
echo This is the no area
pause
exit /b
:getpwd
set "ssid=%*"
for /f "tokens=2delims=:" %%i in ('netsh wlan show profile name^="%ssid:"=%" key^=clear ^| findstr /C:"Key Content"') do echo ssid: %ssid% pass: %%i
Epicurieux.
You cannot use %%i outside of the for loop. it is a temporary variable used by for. You don't need to use multiple labels either, just ask beforehand if you want to save to file:
#echo off & set outfile=
setlocal enabledelayedexpansion
if not exist list.txt echo Output of Wifi password grabber.bat>list.txt
choice /c yn /M "would you like log SSID results to file?
if not errorlevel 2 set "outfile=>>list.txt"
for /f "tokens=2*delims=:" %%a in ('netsh wlan show profile ^|find /i "All User Profile"') do (
set "ssid=%%~a"
for /f "tokens=2*delims=:" %%i in ('netsh wlan show profile name^="!ssid:~1!" key^=clear ^| findstr /C:"Key Content"') do (echo ssid: "!ssid:~1!" pass: %%i)%outfile%
)
or without setting variables in the for loops and without the need for delayedexpansion
#echo off & set outfile=
if not exist list.txt echo Output of Wifi password grabber.bat>list.txt
choice /c yn /M "would you like log SSID results to file?
if not errorlevel 2 set "outfile=>>list.txt"
for /f "tokens=2*delims=:" %%a in ('netsh wlan show profile ^|find /i "All User Profile"') do for /f "tokens=2*delims=:" %%i in ('netsh wlan show profile name^=%%a key^=clear ^| findstr /C:"Key Content"') do (echo ssid: %%a pass: %%i)%outfile%
As a result of my comment, (beneath the other currently existing answer), I searched my script personal collection for an example of something similar.
The following, (which may fail if certain things do not match the specific criteria under which this was designed), is intended to return the Profile name, the Interface name, the SSID, and the password Key.
Other than the addition of the 'results to file' portion of the code, it is tested on Windows 8+ [English]
#Echo Off
SetLocal EnableExtensions DisableDelayedExpansion
Set "LDN=_tmp"
For /F Tokens^=*^ Delims^=^ EOL^= %%G In ('Dir "%TEMP%" /B /A:D /O:N 2^>NUL'
) Do Set "LDN=%%G%LDN%"
MD "%TEMP%\%LDN%" 2>NUL || GoTo :EOF
For /F "Delims==" %%G In ('%SystemRoot%\System32\wbem\WMIC.exe OS Call /? ^|
%SystemRoot%\System32\find.exe "=="') Do Set "HT=%%G"
(Set LF=^
% 0x0A %
)
For /F %%G In ('Copy /Z "%~f0" NUL') Do Set "CR=%%G"
%SystemRoot%\System32\choice.exe /M "Print WLAN Profile results to file"
If ErrorLevel 2 (Set "FOD=CON") Else Set "FOD=%~dp0list.txt"
For /F Tokens^=2^,4^ Delims^=^" %%G In ('%SystemRoot%\System32\netsh.exe WLAN
export profile key^=clear folder^="%TEMP%\%LDN%"') Do (Set "_=%%~nH"
Set "{="
For /F "Tokens=* Delims=" %%I In ('%SystemRoot%\System32\cmd.exe /V /S /D
/C %SystemRoot%\System32\findstr.exe /R /I /C:"<keyMaterial>"^
/C:".*!CR!*!LF![\ \%HT:~-1%]*<\/SSID>" "%%H"') Do (Set "]=%%I"
SetLocal EnableDelayedExpansion
If "!]:~-6,1!" == "/" (For %%J In ("!]:~,-7!") Do (EndLocal
Set "}=%%~J")) Else For %%J In ("!]:~,-14!") Do (EndLocal
Set "{=%%~J")
If Defined { (SetLocal EnableDelayedExpansion
For /F Tokens^=*^ Delims^=^ EOL^= %%K In ('
Echo(^| Set /P "=!_:-%%G="^&:"!" 0^<NUL') Do (
(Echo Name="%%G" Interface="%%K" SSID="!}:*>=!" Key="!{:*>=!"
) 1>>"%FOD%" & EndLocal))))
RD /Q /S "%TEMP%\%LDN%"
If /I "%FOD%" == "CON" (Setlocal EnableDelayedExpansion
For /F "Tokens=1,2" %%G In ("!CMDCMDLINE!") Do (Endlocal
If /I "%%~nG" == "cmd" If /I "%%~H" == "/C" Pause))
EndLocal
GoTo :EOF
The file list.txt, if you choose to write to one, will be located along side the batch file, %~dp0, it should create it if it does not exist, or add to it, if it does.

Undetectable issue with large multi-color batch ascii art

I'm having a strange issue where some large multi-colored ascii art will display irregularly, either only displaying the bottom 1/5 or so of the art, or the top 9 lines of the art if they are commented and un-commented.
The following batch code is being used to multi-color stuff.
:c
setlocal enableDelayedExpansion
:colorPrint Color Str [/n]
setlocal
set "s=%~2"
call :colorPrintVar %1 s %3
exit /b
:colorPrintVar Color StrVar [/n]
if not defined DEL call :initColorPrint
setlocal enableDelayedExpansion
pushd .
':
cd \
set "s=!%~2!"
for %%n in (^"^
^") do (
set "s=!s:\=%%~n\%%~n!"
set "s=!s:/=%%~n/%%~n!"
set "s=!s::=%%~n:%%~n!"
)
for /f delims^=^ eol^= %%s in ("!s!") do (
if "!" equ "" setlocal disableDelayedExpansion
if %%s==\ (
findstr /a:%~1 "." "\'" nul
<nul set /p "=%DEL%%DEL%%DEL%"
) else if %%s==/ (
findstr /a:%~1 "." "/.\'" nul
<nul set /p "=%DEL%%DEL%%DEL%%DEL%%DEL%"
) else (
>colorPrint.txt (echo %%s\..\')
findstr /a:%~1 /f:colorPrint.txt "."
<nul set /p "=%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%"
)
)
if /i "%~3"=="/n" echo(
popd
exit /b
:initColorPrint
for /f %%A in ('"prompt $H&for %%B in (1) do rem"') do set "DEL=%%A %%A"
<nul >"%cd%\'" set /p "=."
subst ': "%cd%" >nul
exit /b
:cleanupColorPrint
2>nul del "%cd%\'"
2>nul del "%cd%\colorPrint.txt"
>nul subst ': /d
exit /b
https://pastebin.com/Z1CKjwWR
but the real meat of the issue comes with trying to display this anime girl
https://pastebin.com/W0w1AtNN
Is anyone able to tell what causes the display issues, and why? None of my experimentation got me anywhere.

batch file to download and search for an update automaticly. it works. but its printing extra symbols and wont print the beginning

#echo off
cls
Color 0A
if exist index.html del index.html
wget -q --show-progress http://cemu.info/
setlocal disableDelayedExpansion
for /f delims^=^ eol^= %%A in ('findstr /ri /c:"http://cemu.info/releases/" /c:"http://cemu.info/releases/" index.html') do (
set "ln=%%A"
setlocal enableDelayedExpansion
set "ln=!ln:*:=!"
if /i "!ln:~0,5!" equ "http://cemu.info/releases/" (set "ln=!ln:~5!") else set "ln=!ln:* "http://cemu.info/releases/ =!"
for /f %%B in ("!ln!") do if "%%B" neq "" echo "http:%%B" > cemu_ver.txt
endlocal
)
if exist index.html del index.html
notepad.exe cemu_ver.txt
it works but instead of http://cemu.info/releases/cemu_1.8.1.zip
it prints "http://cemu.info/releases/cemu_1.8.1.zip""
(a single " at the beginning and a double "" at the end)
also http: is removed and it bothers me
is there anyway to fix that?
Why so conplicated, use the " as a delimiter and get tokens=2
#echo off
cls
Color 0A
if exist index.html del index.html
wget -q http://cemu.info/
for /f tokens^=2delims^=^" %%A in (
'findstr /i /c:"http://cemu.info/releases/" /c:"http://cemu.info/releases/" index.html'
) Do > cemu_ver.txt Echo:"%%A"
i found a workaround:
#echo off
cls
Color 0A
if exist index.html del index.html
.\bin\wget -q --show-progress http://cemu.info/
setlocal disableDelayedExpansion
for /f delims^=^ eol^= %%A in ('findstr /ri /c:"http://cemu.info/releases/" /c:"http://cemu.info/releases/" index.html') do (
set "ln=%%A"
setlocal enableDelayedExpansion
set "ln=!ln:*:=!"
if /i "!ln:~0,5!" equ "http://cemu.info/releases/" (set "ln=!ln:~5!") else set "ln=!ln:* "http://cemu.info/releases/ =!"
for /f %%B in ("!ln!") do if "%%B" neq "" echo http:%%B > cemu_ver.txt
endlocal
)
if exist index.html call :add-quote
goto skip-quote
:add-quote
set /p cemu_ver=<cemu_ver.txt
echo "%cemu_ver% > cemu_ver.txt
del index.html
(goto) 2>NUL
:skip-quote
notepad.exe cemu_ver.txt

Why are my special characters not ignored in Quoted Batch? [duplicate]

This question already has answers here:
How to have multiple colors in a Windows batch file?
(13 answers)
Closed 8 years ago.
I'm trying to create some multiline, multi color ascii art in my batch file, using /|\ characters.
However, I think my batch scrip is reading them as commands instead of outputting text only.
*This is based on some coloring code I found here: Batch Color per line
#echo off
SETLOCAL EnableDelayedExpansion
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
set "DEL=%%a"
)
echo TEST
call :ColorText 0a "################################################################################################################################################################"
call :ColorText 1b "^/^|^\"
call :ColorText 0a "################################################################################################################################################################"
goto :eof
:ColorText
echo off
<nul set /p ".=%DEL%" > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1
goto :eof
The special characters have ^ in front of them, and they are in quotes.
How can I get this to print these special characters for my Ascii Art?
Here is the output I get:
F:\>test
TEST
################################################################################
################################################################################
The system cannot find the path specified.
FINDSTR: Cannot open ^^/^^|^^" nul
################################################################################
################################################################################
F:\>
You're using obsolete code. jeb updated his code, then dbenham updated jeb's update. Try this:
#echo off
setlocal
call :initColorPrint
call :ColorPrint 0a "################################################################################################################################################################"
call :ColorPrint 1b "/|\"
call :ColorPrint 0a "################################################################################################################################################################"
call :cleanupColorPrint
exit /b
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:colorPrint Color Str [/n]
setlocal
set "str=%~2"
call :colorPrintVar %1 str %3
exit /b
:colorPrintVar Color StrVar [/n]
if not defined %~2 exit /b
setlocal enableDelayedExpansion
set "str=a%DEL%!%~2:\=a%DEL%\..\%DEL%%DEL%%DEL%!"
set "str=!str:/=a%DEL%/..\%DEL%%DEL%%DEL%!"
set "str=!str:"=\"!"
pushd "%temp%"
findstr /p /A:%1 "." "!str!\..\x" nul
if /i "%~3"=="/n" echo(
exit /b
:initColorPrint
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do set "DEL=%%a"
<nul >"%temp%\x" set /p "=%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%.%DEL%"
exit /b
:cleanupColorPrint
del "%temp%\x"
exit /b

batch file to mask input with * without an external file

i need batch file to mask the input with * without external file and i need the code to be fast to write letters
FOR EXAMPLE:
#echo off
set char=*
set /p variable=Enter your password:
set char=%variable%
echo %char%
pause
Here is a way to do it using Powershell in a batch file
#echo off
set "psCommand=powershell -Command "$pword = read-host 'Enter Password' -AsSecureString ; ^
$BSTR=[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pword); ^
[System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)""
for /f "usebackq delims=" %%p in (`%psCommand%`) do set password=%%p
echo %password%
Powershell is installed by default on all newer OS's so it's a good compromise. If you have to support XP machines, you can do something similar with VBScript.
Yes! There is a way in pure batch, with misusing of xcopy and prompt command we can do it
#echo off
setlocal enabledelayedexpansion
call:show "Enter your passwordÿ" "0a"
call:hidePass
set /p password=<_tmp&del _tmp&echo/
echo/%password%
pause>nul
exit
:hidePass
set "str="
set "chars="
:writing
set "key="
for /F "usebackq delims=" %%L in (`xcopy /L /w "%~f0" "%~f0" 2^>NUL`) do (
if not defined key set "key=%%L"
)
setlocal EnableDelayedExpansion
set "key=!key:~-1!"
if "%key%" == "" (echo/!str!>_tmp&exit/b)
call:show "-" "0c"
set "str=!str!!key!"
goto :writing
:show
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 %~2 "%~1"
exit/b
:ColorText
<nul set /p ".=%DEL%" > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1
exit/b
The only problem is you can not use * as mask, in this case I'm using -

Resources