r/Batch • u/Intrepid_Ad_4504 • Aug 11 '26
r/Batch • u/kitwiller_o • Jan 10 '24
Show 'n Tell Batch + IrfanView, Contextual menu conversion from HEIC to JPEG
**Problem:**
My phone saves pictures in HEIC format and I like it to keep it this way (not the point of the post).My computer syncs automatically the pictures but when I have to share pictures via email or with other people, the HEIC format make some users twitch (expecially on old company computers).
**Previous method:**
To convert the HEIC to JPEG i used the batch conversion from IrfanView which involved the following steps: Opening a picture from the folder using IrfanView, pressing "B" to enter "batch" mode, and select the file/options to convert to JPEG.
**New Method:**
Select the files, Right-click to get the context menu -> ConvertToJPEG. Done.
**How:**
I created the following bat
u/echo off
SETLOCAL ENABLEDELAYEDEXPANSION
FOR %%A IN (%*) DO (
"C:\Program Files\IrfanView\i_view64.exe" "%%~fA" /convert="%%~dpnA.jpg"
)Then in regedit I created the keys to:
Computer\HKEY_CLASSES_ROOT\SystemFileAssociations\.heic\Shell\Convert to JPEG\Command\
and to the String (Default) i gave the value of
"C:\projects\HEIC convert\ConvertToJPEG.bat" "%1"
Now when I right click one or multiple HEIC files I have the option to convert from the context menu without installing additional software using the IrfanView command line option I already use for many other things.
As this can be used for many other things, I though it could be helpful to some.
Have fun.
r/Batch • u/windows-cli • Jan 25 '26
Show 'n Tell Interactive online course to learn Batch
I couldn’t find any good way to learn Windows CLI hands-on, so I built one myself: https://windows-cli.arnost.org/ It covers the basics of using the Windows command line with guided lessons and real-time practice.
r/Batch • u/Lil_Batti • Jun 09 '25
Wrote a batch script for Windows maintenance – it’s saving me a ton of time
I made a Windows Maintenance Tool in batch — it's simple, clean, and actually useful
Hey everyone,
I’ve been messing around with batch scripting lately and decided to put together a Windows maintenance tool. It’s basically a one-stop script that can help clean up your system, run built-in diagnostics, fix common network issues, and generate system reports — all from one terminal menu.
It started as a personal project for my own use, but it’s become pretty handy, so I figured I’d share it.
What it does:
Run things like SFC, DISM, CHKDSK without digging through menus
Restart network adapters with one click (auto-detects active ones)
Reset Windows Update services (stops + clears cache + restarts)
DNS tools: flush, set Google/Cloudflare, or custom DNS input
Generate full system reports (driver list, system info, IP config) — saved as 3 separate
.txtfiles to keep it organizedOption to clean up temp files and do basic optimization
I made sure nothing destructive runs silently — most of it uses built-in Windows tools like netsh, ipconfig, systeminfo, etc.
Why I made it:
I got tired of typing the same commands every time someone had a problem, so this just automates everything. It’s also a nice little project for learning batch scripting.
If anyone wants to try it or has feedback, Download link: https://github.com/ios12checker/Windows-Maintenance-Tool
Let me know if there's anything you'd add or improve — I’m still updating it.

r/Batch • u/thelowsunoverthemoon • Mar 05 '21
Show 'n Tell Pacman in pure Batch
I was bored today and I tried implementing a simple Pacman in Batch using VT100 escape sequences. I did simplify a lot of the rules, but the basic game is there. Here are the major changes:
No "ghost house"; eaten ghosts reset all at once after the powerup wears off
Ghosts turn white after eating powerup, and turn dark blue to signal the powerup is wearing off
Ghosts all have the same basic behavior
No fruits
Due to the method of input used, the controls lag/miss keys sometimes. As well, it's pretty much impossible to win unless you manually adjust the speed variable to a really high number, so I didn't bother implementing a win detection. It's more of a proof of concept than anything.
The script also adjusts reg keys to use Lucida Console font instead of the default Consolas, to give it a more retro feel. If you don't want that, then just replace the first IF with
IF not "%1" == "" (
GOTO :%1
)You MUST save it in UTF-8 encoding for the characters to display properly, and also have Windows 10 for VT100 sequences. Use WASD to move.
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
IF "%1" == "" (
>NUL REG ADD HKCU\Console\PacMan /v FaceName /t REG_SZ /d "Lucida Console" /f
START "PacMan" "%~0" Font
EXIT
) else IF "%1" == "Font" (
>NUL REG DELETE HKCU\Console\PacMan /f
) else (
GOTO :%1
)
TITLE PacMan
MODE 30, 30
(CHCP 65001)>NUL
CALL :MACROS
SET "direction=W A S D"
SET "mov[W]=y]-=1"
SET "mov[A]=x]-=1"
SET "mov[S]=y]+=1"
SET "mov[D]=x]+=1"
SET "ghost[blinky]=%col:c=255;0;0%▓"
SET "ghost[inky]=%col:c=0;255;255%▓"
SET "ghost[pinky]=%col:c=255;184;255%▓"
SET "ghost[clyde]=%col:c=255;184;82%▓"
SET "ghost[base]= inky blinky pinky clyde "
SET "ghost[cur]=%ghost[base]%"
SET "map[pelbou]= "
SET "map[powerup]=.6$7..6$23..22$7..22$23."
SET map[classic]="1-19"."1-1" "19-19"."1-1" "3-4" "6-8" "12-14" "16-17" "19-19"."1-1" "19-19"."1-1" "3-4" "6-8" "12-14" "16-17" "19-19"."1-1" "19-19"."1-4" "6-8" "12-14" "16-19"."4-4" "6-6" "14-14" "16-16"."1-4" "6-6" "8-8" "12-12" "14-14" "16-19"."1-1" "8-8" "12-12" "19-19"."1-4" "6-6" "8-8" "12-12" "14-14" "16-19"."4-4" "6-6" "14-14" "16-16"."1-4" "6-8" "12-14" "16-19"."1-1" "19-19"."1-1" "3-4" "6-8" "12-14" "16-17" "19-19"."1-1" "19-19"."1-1" "3-4" "6-8" "12-14" "16-17" "19-19""1-19"."1-1" "19-19"."1-19"
SET /A "char[x]=d[x]=15","char[y]=d[y]=6", "pac[invinc]=0", "score=0"
SET /A "inky[x]=inky[st]=14", "inky[y]=14", "clyde[x]=clyde[st]=15", "clyde[y]=14", "blinky[x]=blinky[st]=15", "blinky[y]=12", "pinky[x]=pinky[st]=16", "pinky[y]=14"
CALL :CREATEMAP classic powerup
ECHO %ESC%[?25l%col:c=229;235;52%%ESC%[8;11HDIFFICULTY%ESC%[10;11H[A] EASY%ESC%[12;11H[B] NORMAL%ESC%[14;11H[C] HARD
(CHOICE /C ABC /N)>NUL
IF %errorlevel% EQU 1 (
SET "speed=55"
) else IF %errorlevel% EQU 2 (
SET "speed=45"
) else (
SET "speed=35"
)
:MENU
SETLOCAL
DEL "%~dpn0.quit" 2>NUL
"%~F0" CONTROL W >"%temp%\%~n0_signal.txt" | "%~F0" GAME <"%temp%\%~n0_signal.txt"
ECHO %ESC%[25;6H[A] TO REPLAY%ESC%[26;6H[B] TO EXIT
(CHOICE /C AB /N)>NUL
IF %errorlevel% EQU 1 (
ENDLOCAL
GOTO :MENU
)
EXIT
:GAME
ECHO %ESC%[2J%ESC%[5;6H%pel[disp]%%ESC%[5;5H%map[disp]%%ESC%[%char[y]%;%char[x]%H%col:c=229;235;52%█
FOR /L %%Q in (3, -1, 0) DO (
IF %%Q EQU 0 (
ECHO %ESC%[24;13HSTART
) else (
ECHO %ESC%[24;15H%%Q
)
FOR /L %%J in (1, 3, 1000000) DO REM
)
FOR /L %%# in () DO (
SET /P "input="
IF defined input (
2>NUL SET /A !every:#=20! || (
FOR %%A in (!input!) DO (
SET /A "d[x]=char[x]", "d[y]=char[y]", "d[!mov[%%A]!"
FOR %%Q in (".!d[y]!$!d[x]!.") DO (
IF "%map[bou]%" == "!map[bou]:%%~Q=!" (
IF not "!map[powerbou]:%%~Q=!" == "!map[powerbou]!" (
SET /A "pac[invinc]=4", "score+=50"
SET "map[powerbou]=!map[powerbou]:%%~Q=!"
) else IF "!map[pelbou]:%%~Q=!" == "!map[pelbou]!" (
SET /A "score+=10"
SET "map[pelbou]=!map[pelbou]!%%~Q"
)
ECHO %ESC%[!char[y]!;!char[x]!H
SET /A "char[!mov[%%A]!"
)
)
)
)
)
2>NUL SET /A !every:#=%speed%! || (
SET "ghost[disp]="
IF !pac[invinc]! GTR 2 (
SET "ghost[add]=%col:c=255;255;255%▒"
) else IF !pac[invinc]! GTR 0 (
SET "ghost[add]=%col:c=10;18;148%▒"
) else (
SET "ghost[add]=#"
)
FOR %%G in (!ghost[cur]!) DO (
SET "ghost[dir]=N"
SET /A "d[x]=%%G[x] - char[x]", "d[y]=%%G[y] - char[y]"
IF !pac[invinc]! GTR 0 (
IF !d[y]! LSS 0 (
SET "ghost[dir]=W"
) else IF !d[y]! GTR 0 (
SET "ghost[dir]=S"
)
IF "!ghost[dir]!" == "N" (
IF !d[x]! LSS 0 (
SET "ghost[dir]=A"
) else IF !d[x]! GTR 0 (
SET "ghost[dir]=D"
)
)
) else (
IF !d[y]! LSS 0 (
SET "ghost[dir]=S"
) else IF !d[y]! GTR 0 (
SET "ghost[dir]=W"
)
IF "!ghost[dir]!" == "N" (
IF !d[x]! LSS 0 (
SET "ghost[dir]=D"
) else IF !d[x]! GTR 0 (
SET "ghost[dir]=A"
)
)
)
FOR %%A in (!ghost[dir]!) DO (
SET /A "d[x]=%%G[x]", "d[y]=%%G[y]", "d[!mov[%%A]!"
FOR /F "tokens=1-2" %%Q in (".!%%G[y]!$!%%G[x]!. .!d[y]!$!d[x]!.") DO (
IF "%map[bou]%" == "!map[bou]:%%~R=!" (
IF not "!map[powerbou]:%%~Q=!" == "!map[powerbou]!" (
SET "ghost[disp]=!ghost[disp]!%col:c=222;161;133%%ESC%[!%%G[y]!;!%%G[x]!H○"
) else IF "!map[pelbou]:%%~Q=!" == "!map[pelbou]!" (
SET "ghost[disp]=!ghost[disp]!%col:c=222;161;133%%ESC%[!%%G[y]!;!%%G[x]!H•"
) else (
SET "ghost[disp]=!ghost[disp]!%ESC%[!%%G[y]!;!%%G[x]!H "
)
SET /A "%%G[!mov[%%A]!"
) else (
SET "dir[count]=0"
SET "dir[pos]="
FOR %%D in (!direction:%%A^=!) DO (
SET /A "d[x]=%%G[x]", "d[y]=%%G[y]", "d[!mov[%%D]!"
FOR %%N in (".!d[y]!$!d[x]!.") DO (
IF "%map[bou]%" == "!map[bou]:%%~N=!" (
SET /A "dir[count]+=1"
SET "dir[!dir[count]!]=%%D"
)
)
)
SET /A "dir[rand]=(!RANDOM! %% dir[count]) + 1"
FOR %%K in (!dir[rand]!) DO (
FOR %%P in (!dir[%%K]!) DO (
IF not "!map[powerbou]:%%~Q=!" == "!map[powerbou]!" (
SET "ghost[disp]=!ghost[disp]!%col:c=222;161;133%%ESC%[!%%G[y]!;!%%G[x]!H○"
) else IF "!map[pelbou]:%%~Q=!" == "!map[pelbou]!" (
SET "ghost[disp]=!ghost[disp]!%col:c=222;161;133%%ESC%[!%%G[y]!;!%%G[x]!H•"
) else (
SET "ghost[disp]=!ghost[disp]!%ESC%[!%%G[y]!;!%%G[x]!H "
)
SET /A "%%G[!mov[%%P]!"
)
)
)
)
)
IF "!ghost[add]!" == "#" (
SET "ghost[disp]=!ghost[disp]!%ESC%[!%%G[y]!;!%%G[x]!H!ghost[%%G]!"
IF "!%%G[y]!$!%%G[x]!" == "!char[y]!$!char[x]!" (
ECHO %ESC%[24;6HGAME OVER, PRESS [W]
(COPY NUL "%~dpn0.quit")>NUL
EXIT
)
) else (
IF "!%%G[y]!$!%%G[x]!" == "!char[y]!$!char[x]!" (
SET /A "%%G[y]=14", "%%G[x]=%%G[st]", "score+=200"
SET "ghost[cur]=!ghost[cur]: %%G =!"
) else (
SET "ghost[disp]=!ghost[disp]!%ESC%[!%%G[y]!;!%%G[x]!H!ghost[add]!"
)
)
)
)
2>NUL SET /A !every:#=500! || (
IF !pac[invinc]! GTR 0 (
SET /A "pac[invinc]-=1"
IF !pac[invinc]! EQU 0 (
SET "ghost[cur]=!ghost[base]!"
)
)
)
2>NUL SET /A !every:#=2! && (
SET "pac[col]=%col:c=229;235;52%"
) || (
SET "pac[col]=%col:c=194;157;12%"
)
ECHO %ESC%[4;6H%col:c=255;255;255%!score!!pac[col]!%ESC%[!char[y]!;!char[x]!H█!ghost[disp]!
SET /A "frame+=1"
)
:CREATEMAP <map> <powerup>
SETLOCAL
SET "map[data]=!map[%~1]!" & SET "map[count]=1"
SET map[!map[count]!]=%map[data]:.= & SET /A map[count]+=1 & SET map[!map[count]!]=%
FOR /L %%G in (1, 1, 19) DO (
SET "pel[line]=!pel[line]!•"
)
FOR /L %%# in (1, 1, %map[count]%) DO (
SET "pel[disp]=!pel[disp]!%pel[line]%%dn:n=1%%bk:n=19%"
FOR %%Q in (!map[%%#]!) DO (
FOR /F "tokens=1-2 delims=-" %%A in ("%%~Q") DO (
SET "map[disp]=!map[disp]!%ESC%[5G%ESC%[%%AC"
FOR /L %%P in (%%A, 1, %%B) DO (
SET /A "d[y]=%%# + 4","d[x]=%%P + 5"
SET "map[bou]=!map[bou]!.!d[y]!$!d[x]!"
SET "map[disp]=!map[disp]!█"
)
)
)
SET "map[disp]=!map[disp]!%dn:n=1%%ESC%[5G"
)
FOR %%Q in (!map[%~2]:.^= !) DO (
FOR /F "tokens=1-2 delims=$" %%A in ("%%Q") DO (
SET "pel[disp]=!pel[disp]!%ESC%[%%A;%%BH○"
)
)
ENDLOCAL & SET "map[disp]=%col:c=33;33;222%%map[disp]%" & SET "map[bou]=%map[bou]%." & SET "map[powerbou]=!map[%~2]!" & SET "pel[disp]=%col:c=222;161;133%%pel[disp]%"
GOTO :EOF
:CONTROL
FOR /L %%C in () do (
FOR /F "tokens=*" %%A in ('CHOICE /C:WASD /N') DO (
IF exist "%~dpn0.quit" (
DEL "%~dpn0.quit"
EXIT
)
<NUL SET /P ".=%%A"
)
)
GOTO :EOF
:MACROS
FOR /F %%A in ('ECHO prompt $E^| cmd') DO SET "ESC=%%A"
SET every="1/((frame %% #)^0)"
SET "col=%ESC%[38;2;cm"
SET "up=%ESC%[nA"
SET "dn=%ESC%[nB"
SET "bk=%ESC%[nD"
SET "nx=%ESC%[nC"
GOTO :EOFr/Batch • u/Intrepid_Ad_4504 • Sep 13 '26
Show 'n Tell Missile Command - Batch port of 1980s Atari arcade game
r/Batch • u/pc1350 • Aug 26 '26
Looking for a Analog clock.bat by theBATeam . org
DO NOT CLICK on the link in the video description!
Anyone has this .bat file? Author's github (Batch-Man · GitHub) does not have it (or I can't find it). Thank you.
r/Batch • u/MaybeBirb • Jul 16 '26
Show 'n Tell How much batchscript is too much batchscript?
Currently have 1,376 lines of batchscript in this one file. Kinda built myself a little state machine at this point. Memes aside, is there a particular reason huge batchscript files would be a bad idea? I usually only ever see very small ones, and I'm not entirely sure why
(Not too serious a question, so not tagged as one)
r/Batch • u/FAMICOMASTER • Nov 19 '25
Show 'n Tell My fully modular, color tilemapped game engine, DIM2
Hello all. I recently joined this sub, I can't believe I didn't know it existed until today. I've spent years working with Batch scripts and have done lots of what I think are interesting projects in "pure" batch (without any extensions, everything is done entirely in the scripting language).
DIM2 is one of them, I haven't really "finished" it per se, as there's no gameplay or physics implemented. Right now, this is more like a graphics demo that you happen to be able to scroll around.
All three windows you see in the screenshot are taken with the exact same script - The engine script will load a document list which points to files in another directory containing the full tileset and map data. Multiple data types can be combined into a single "blob" file, but for now I have them loaded separately. This is done completely automatically on startup and you can force reload the entire engine from these files, meaning you can leave the engine running, make changes to the tileset, and instantly see them without ever closing the script.
I was intending on making this into a real, released game engine, but life got in the way and I stopped active development over a year ago. If there's interest, I might do some more work on it.
The three games shown are Pokemon Blue (this is the southern edge of Pallet Town), Robo-Rally (the board "Dizzy Highway") and the central castle from another unfinished game I previously made in batch which actually spawned this project, Phantasma.
r/Batch • u/anic17_ • Oct 16 '20
Show 'n Tell Batch Antivirus
Hello, I present here my Batch Antivirus, it's pretty good for being fully coded in batch.
Antivirus features:
Scanner:
It uses a database, gets the hash of the scanned file, and if it's found on the DB then quarantine it and say it's malware.
Real-time protection:
Does the same as scanner except that it uses a batch plugin that registers any change on the file system (Create, Rename, Modify, Move...)
Web protection:
Uses NETSTAT to get connections to the PC. Then, it scans IP in another database. If IP is found, alert. I'm implementing a system where it closes the TCP connection.
Heuristic Analyzer:
It searches for strings/API calls on batch files, DNS, and HTTP requests. On batch files, it also searches for PING, CURL, fork bombs, and suspicious behavior.
It doesn't check by filenames nor extensions, it checks by hash.
Batch Antivirus GitHub repository
What do you think, and what improvements can it have?
r/Batch • u/T3RRYT3RR0R • Sep 04 '26
Show 'n Tell Load animation
This is an example of using multithreading to display an animation while the main script continues execution. The animation itself is part of my ongoing experimantion with programmable entity behaviours that can be implemented via set /a, and is just 2 'entities' moving through their programmed paths.
Code available at: https://github.com/T3RRYT3RR0R/Advanced_Batch/blob/main/Load_Animation.bat
r/Batch • u/thelowsunoverthemoon • Sep 06 '21
Show 'n Tell Flappy Bird in pure Batch
I haven't done anything in Batch for a while, so I thought it'd be fun to remake another simple game : Flappy Bird. Depending on your computer, it may be faster or slower, but you can always change the values in the %every% macro to make it faster or slower ("every" N frame do this, so every 2 frames is faster than every 3 frames). I was too lazy to do any frame capping, but I did add some clouds and randomized bird colours just to keep it faithful to the original.
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
IF "%1" == "" (
>NUL REG ADD HKCU\Console\Flappy /V FaceName /T REG_SZ /D "Lucida Console" /F
>NUL REG ADD HKCU\Console\Flappy /V FontSize /T REG_DWORD /D 0x00180008 /F
START "Flappy" "%~0" Font
EXIT
) else IF "%1" == "Font" (
>NUL REG DELETE HKCU\Console\Flappy /f
) else (
GOTO :%1
)
MODE 30, 25
(CHCP 65001)>NUL
FOR /F %%A in ('ECHO PROMPT $E^| CMD') DO SET "ESC=%%A"
SET "up=%ESC%[nA"
SET "dn=%ESC%[nB"
SET "bk=%ESC%[nD"
SET "nx=%ESC%[nC"
SET "exit=ECHO %dn:n=1%%ESC%[48;2;55;128;128m%ESC%[38;2;212;172;87m%nx:n=4%Press W to Continue :(^&(COPY NUL "%~dpn0.quit")^>NUL^&EXIT ^!score^!"
SET "every=SET /A "d[num]=frame %% #"& IF ^!d[num]^! EQU 0"
SET col[full]="200;133;222" "203;204;124" "121;199;173"
SET bird[full]="\█" "─█" "/█"
SET "pipe[bdy]=║"
SET "pipe[top]=╥"
SET "pipe[btm]=╨"
SET "pipe[max]=%pipe[bdy]%%bk:n=1%%dn:n=1%%pipe[bdy]%%bk:n=1%%dn:n=1%%pipe[bdy]%%bk:n=1%%dn:n=1%%pipe[bdy]%%bk:n=1%%dn:n=1%%pipe[bdy]%%bk:n=1%%dn:n=1%%pipe[bdy]%%bk:n=1%%dn:n=1%%pipe[bdy]%%bk:n=1%%dn:n=1%%pipe[bdy]%%bk:n=1%%dn:n=1%%pipe[bdy]%%bk:n=1%%dn:n=1%%pipe[bdy]%%bk:n=1%%dn:n=1%%pipe[bdy]%%bk:n=1%%dn:n=1%%pipe[bdy]%%bk:n=1%%dn:n=1%%pipe[bdy]%%bk:n=1%%dn:n=1%%pipe[bdy]%%bk:n=1%%dn:n=1%%pipe[bdy]%%bk:n=1%%dn:n=1%%pipe[bdy]%%bk:n=1%%dn:n=1%%pipe[bdy]%%bk:n=1%%dn:n=1%"
SET "cloud[1]=%dn:n=2%█"
SET "cloud[2]=%dn:n=1%█%dn:n=1%%bk:n=1%█"
SET "cloud[3]=█%dn:n=1%%bk:n=1%█%dn:n=1%%bk:n=1%█"
SET "cloud[4]=█%dn:n=1%%bk:n=1%█%dn:n=1%%bk:n=1%█"
SET "cloud[5]=█%dn:n=1%%bk:n=1%█%dn:n=1%%bk:n=1%█"
SET "cloud[6]=%dn:n=1%█%dn:n=1%%bk:n=1%█"
SET "cloud[7]=%dn:n=2%█"
FOR %%G in (col bird) DO (
FOR %%B in (!%%G[full]!) DO (
SET /A "d[num]+=1"
SET "%%G[!d[num]!]=%%~B"
)
SET "d[num]=0"
)
FOR /L %%G in (1, 1, 7) DO (
FOR /L %%Q in (%%G, 1, 7) DO (
SET "cld[end][%%G]=!cld[end][%%G]!!cloud[%%Q]!%up:n=2%"
)
FOR /L %%Q in (1, 1, %%G) DO (
SET "cld[bgn][%%G]=!cld[bgn][%%G]!!cloud[%%Q]!%up:n=2%"
)
)
SET "bird[cur]=%bird[1]%"
SET /A "bird[frame]=0", "bird[y]=14", "frame=pipe[num]=0", "bird[rand]=(%RANDOM% %% 3) + 1", "score=0", "score[high]=0"
DEL "%~dpn0.quit" 2>NUL
:START
SETLOCAL
TITLE Flappy Bird
ECHO %ESC%[?25l%ESC%[48;2;55;128;128m%ESC%[2J%ESC%[38;2;212;172;87m%ESC%[8;11HFLAPPY BIRD%ESC%[9;9HHigh Score : !score[high]!%ESC%[11;9H[Press any Key]%ESC%[%bird[y]%;10H%ESC%[38;2;!col[%bird[rand]%]!m%bird[cur]%%ESC%[23;1H%ESC%[48;2;50;168;82m%ESC%[38;2;133;110;48m▲_▲_▲_▲_▲_▲_▲_▲_▲_▲_▲_▲_▲_▲_▲_%ESC%[0m
PAUSE>NUL
"%~F0" CONTROL W >"%temp%\%~n0_signal.txt" | "%~F0" GAME <"%temp%\%~n0_signal.txt"&SET "score=!ERRORLEVEL!"
IF %score% GTR %score[high]% (
SET "score[high]=%score%"
)
ENDLOCAL&SET "score[high]=%score%"
GOTO :START
:GAME
TITLE Press W to Jump
FOR /L %%# in () DO (
SET /P "input="
IF defined input (
SET "bird[jmp]=5"
SET "input="
)
%every:#=5% (
IF !bird[frame]! EQU 3 (
SET "bird[frame]=1"
) else (
SET /A "bird[frame]+=1"
)
FOR %%F in (!bird[frame]!) DO (
SET "bird[cur]=!bird[%%F]!"
)
)
%every:#=30% (
SET "pipe[disp]="
FOR %%P in (!pipe[list]!) DO (
FOR /F "tokens=1-5 delims=;" %%A in ("!pipe%%P!") DO (
IF %%C EQU 1 (
SET "pipe[list]=!pipe[list]:%%P=!"
) else (
IF %%C EQU 10 (
IF !bird[y]! LEQ %%D (
%exit%
) else IF !bird[y]! GEQ %%E (
%exit%
)
SET /A "score+=1"
TITLE Score : !score!
)
SET "pipe[disp]=!pipe[disp]!%ESC%[1;%%CH!pipe[max]:~0,%%A!%dn:n=1%%pipe[btm]%%dn:n=5%%bk:n=1%%pipe[top]%%dn:n=1%%bk:n=1%!pipe[max]:~0,%%B!"
SET /A "d[num]=%%C - 1"
SET "pipe%%P=%%A;%%B;!d[num]!;%%D;%%E"
)
)
)
)
%every:#=20% (
SET "cld[disp]="
FOR %%P in (!cld[list]!) DO (
FOR /F "tokens=1-3 delims=;" %%A in ("!cld%%P!") DO (
IF %%C EQU 1 (
SET "cld[disp]=!cld[disp]!%ESC%[%%A;%%CH"
SET "cld[disp]=!cld[disp]!!cld[end][%%B]!
SET /A "cld[adj]=%%B + 1"
IF !cld[adj]! EQU 8 (
SET "cld[list]=!cld[list]:%%P=!"
) else (
SET "cld%%P=%%A;!cld[adj]!;%%C"
)
) else (
SET "cld[disp]=!cld[disp]!%ESC%[%%A;%%CH"
SET "cld[disp]=!cld[disp]!!cld[bgn][%%B]!
SET /A "d[num]=%%C - 1", "cld[adj]=%%B"
IF %%C GTR 23 (
SET /A "cld[adj]+=1"
) else IF !d[num]! EQU 1 (
SET "cld[adj]=1"
)
SET "cld%%P=%%A;!cld[adj]!;!d[num]!"
)
)
)
IF !bird[jmp]! NEQ 0 (
IF !bird[y]! EQU 1 (
SET "bird[jmp]=0"
) else (
SET /A "bird[jmp]-=1", "bird[y]-=1"
)
) else (
%every:#=5% (
IF !bird[y]! NEQ 22 (
SET /A "bird[y]+=1"
) else (
%exit%
)
)
)
)
%every:#=250% (
SET /A "pipe[rand]=!RANDOM! %% 5"
IF !pipe[rand]! EQU 0 (
SET /A "pipe[num]+=1", "pipe[rand]=(!RANDOM! %% 15) + 1", "d[num]=(9 * pipe[rand]) - 1", "d[adj]=((21 - (pipe[rand] + 5)) * 9) - 1", "d[max]=pipe[rand] + 5"
SET "pipe[!pipe[num]!]=!d[num]!;!d[adj]!;29;!pipe[rand]!;!d[max]!"
SET "pipe[list]=!pipe[list]! [!pipe[num]!]"
)
)
%every:#=275% (
SET /A "cld[rand]=!RANDOM! %% 3"
IF !cld[rand]! EQU 0 (
SET /A "cld[num]+=1", "cld[rand]=(!RANDOM! %% 17) + 2"
SET "cld[!cld[num]!]=!cld[rand]!;1;29"
SET "cld[list]=!cld[list]! [!cld[num]!]"
)
)
ECHO %ESC%[48;2;55;128;128m%ESC%[22;30H%ESC%[1J%ESC%[38;2;255;255;255m!cld[disp]!%ESC%[!bird[y]!;10H%ESC%[38;2;!col[%bird[rand]%]!m!bird[cur]!%ESC%[48;2;113;191;46m%ESC%[38;2;212;172;87m!pipe[disp]!%ESC%[0m
SET /A "frame+=1"
)
:CONTROL
FOR /L %%C in () do (
FOR /F "tokens=*" %%A in ('CHOICE /C:W /N') DO (
IF exist "%~dpn0.quit" (
DEL "%~dpn0.quit"
EXIT
)
<NUL SET /P ".=%%A"
)
)
GOTO :EOFHave fun,
Lowsun
r/Batch • u/Scared_Confection980 • Oct 24 '26
Show 'n Tell I made a pixel editor in CMD
https://github.com/CodeBreaker-cmd/Batch-Pixel-Editor-/releases
For now it has just the necessary for draw and save your project, Wich you can open like a picture
If you want to use it and there is any bug or anything please let me know, I'm thinking in make it compatible with any code in batch to show the image using the call command
r/Batch • u/thelowsunoverthemoon • Jul 28 '20
Show 'n Tell Prism Song : fantasy platformer in pure Batch!
This was an old platformer script I found, so I polished it a bit and added some more details. Prism Song is a boss rush platformer with NPCs, interactive objects, and a plot. It is multithreaded, so the controls should be fairly responsive. However, since the "graphics" are all text based, it's easy to fall down and miss. The hitboxes are also pretty general since I didn't want to make one for each sprite.
Here is a pastebin for the full code. All you have to do is copy and paste, and save it in a .bat file. MAKE SURE it's in UTF-8 encoding, or the Unicode characters won't display properly.
IMPORTANT : it seems pastebin adds a space in after newline. So on this line
SET ^"LF=^
^" Above empty line is required - do not removeTake out the space in the blank line, or the game won't work.
For images of the script in action, you can visit here. You can download a sound version in there as well, with a sound effects and music added on. (via VBScript)
https://lowsun.itch.io/prism-song
Here are the controls:
A and D : move left and right, changes direction to left and right respectively
S : center direction
W : jump in specified direction
I : change colour
O : special move
P : Interact with NPC's and buildings (totems, shrines, ect)
Have fun,
Lowsun :)
r/Batch • u/T3RRYT3RR0R • Aug 31 '26
Show 'n Tell Random walker
Random walker as an algorithm. See github for full code:
https://github.com/T3RRYT3RR0R/Random_Walker
Edit: New repository link, additional modes added.
xe=(`^=`<<13,`^=`>>17,`^=`<<5,((`&0x7FFFFFFF)%%(_%%i.fH-_%%i.fL+1)))+_%%i.fL ; generate random cd coefficient: xe 'x expiry' Value in range : [ high-low ... + low ]
_%%i.xd=-1*((_%%i.xc-=-1*~((_%%i.xc)>>31))>>31) ; decrease cooldown timer if timer gtr -1 ; flag 'do' true : xd == 1 if cd == -1
_%%i.xc+=_%%i.xd*(xe+1) ; new cd value added from xe if xd == 1
rx=('^='<<13,'^='>>17,'^='<<5,(('&0x7FFFFFFF)%%3+1))-2 ; generate random sign x -1 0 or 1
_%%i.sx=_%%i.xd*rx+((1-_%%i.xd)*_%%i.sx) ; selectively assign new sx if xd == 1
ye=('^='<<13,'^='>>17,'^='<<5,(('&0x7FFFFFFF)%%(_%%i.fH-_%%i.fL+1)))+_%%i.fL ; repeat above logic for y using a different random seed
_%%i.yd=-1*((_%%i.yc-=-1*~((_%%i.yc)>>31))>>31)
_%%i.yc+=_%%i.yd*(ye+1)
ry=(`^=`<<13,`^=`>>17,`^=`<<5,(('&0x7FFFFFFF)%%3+1))-2
_%%i.sy=_%%i.yd*ry+((1-_%%i.yd)*_%%i.sy)
_%%i.x+=_%%i.sx,_%%i.x-=(-1*((_%%i.xH-(_%%i.x+_%%i.w))>>31)),_%%i.x+=(-1*((_%%i.x-_%%i.xL)>>31)) ; increment by ( sx - (1 if x gtr x max) + ( 1 if x lss x min )
_%%i.y+=_%%i.sy,_%%i.y-=(-1*((_%%i.yH-(_%%i.y+_%%i.h))>>31)),_%%i.y+=(-1*((_%%i.y-_%%i.yL)>>31)) ; clamped sign modification as above for y
,... F T reset _#.cd 'rc' if:
rc=-(-1*(-1-((_%%i.sx|_%%i.sy)|-(_%%i.sy|_%%i.sx))))|^ ; 0 | -1 sy,sX == 0,0
-(-1*~((_%%i.xL-_%%i.x)>>31))|^ ; 0 | -1 _#.x == min X
-(-1*((_%%i.xH-(_%%i.x+_%%i.w))>>31)-1)|^ ; 0 | -1 _#.x == max x
-(-1*~((_%%i.yL-_%%i.y)>>31))|^ ; 0 | -1 _#.y == min y
-(-1*((_%%i.yH-(_%%i.y+_%%i.h))>>31)-1) ; 0 | -1 _#.y == max y
_%%i.xc|=rc ; xc | -1 rc == -1
_%%i.yc|=rc ; yc | -1 rc == -1r/Batch • u/capoapk • Apr 22 '26
Console GPB
GPB est une plateforme de jeux qui tourne depuis l’invite de commande il y a un script principal qui permet de lancer en Batch, PowerShell et HTML , Chaque jeu est séparé, donc on peut en ajouter facilement sans casser le reste personnalisé pour Windows, fonctionnant directement dans l'invite de commande Il détecte et lance automatiquement stockés dans son dossier Outils intégrés : Il propose une calculatrice visuelle, un chronomètre, un minuteur avec alarme et une barre de recherche internet il utilise des couleurs, des animations d'introduction et force l'affichage en plein écran pour une meilleure immersion C'est un outil pratique et léger
📦 Le projet est dispo ici :
r/Batch • u/thelowsunoverthemoon • Dec 09 '20
Show 'n Tell Snake in pure Batch
I was bored today so I tried my hand at creating Snake. There's been Snake done in pure Batch already here https://www.dostips.com/forum/viewtopic.php?t=4741 by dbenham, but I wanted to make a version that was as simple and minimal as possible. I also wanted to make a version that relied solely on VT100 escape sequences for display.
The following version of Snake in Batch is very simple, and it has non-blocking controls, pellets, ect, everything in a classic Snake game. Also, I made it so that moving in the opposite direction results in a collision, just for that extra challenge. It also has 3 "skins" you can choose from just for fun. To play, just save it in a .bat file and run. You MUST save it in UTF-8 format, or else the Unicode characters show. You can also change up the Snake Speed, but editing the snake[speed] variable. (lower number -> faster)
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
IF not "%1" == "" (
GOTO :%1
)
TITLE Snake
MODE 30, 22
FOR /F %%A in ('ECHO prompt $E^| cmd') DO SET "ESC=%%A"
(CHCP 65001)>NUL
SET "mov[W]=y]-=1"
SET "mov[A]=x]-=1"
SET "mov[S]=y]+=1"
SET "mov[D]=x]+=1"
SET "snake[bou]=.0;0."
SET "skin[1]=%ESC%[38;2;105;78;148m▒$%ESC%[38;2;184;20;184m▓"
SET "skin[2]=%ESC%[38;2;235;180;52m♣$%ESC%[38;2;209;109;38m♥"
SET "skin[3]=%ESC%[38;2;212;38;61m◙$%ESC%[38;2;222;100;116m◘"
SET /A "map[width]=30", "map[height]=15", "char[0][x]=d[x]=3","char[0][y]=d[y]=3","snake[mass]=1","pel[x]=0","snake[speed]=16"
CALL :MAKEMAP %map[width]% %map[height]%
SET "exit=ECHO %ESC%[1;1H%disp[kill]%%ESC%[38;2;255;255;255m%ESC%[%map[height]%;1H%ESC%[3BOuch...Press W to Continue&(COPY NUL "%~dpn0.quit")>NUL&EXIT"
DEL "%~dpn0.quit" 2>NUL
ECHO %ESC%[?25l%ESC%[38;2;255;255;255mChoose your skin&FOR /L %%Q in (1, 1, 3) DO (
ECHO %ESC%[B%ESC%[38;2;255;255;255m[%%Q] !skin[%%Q]:$=!!skin[%%Q]:$=!!skin[%%Q]:$=!
)
(CHOICE /C 123 /N)>NUL
FOR /F "tokens=1-2 delims=$" %%A in ("!skin[%errorlevel%]!") DO (
SET "snake[cha][1]=%%A"&SET "snake[cha][2]=%%B"
)
SET "snake[disp]=%ESC%[%char[0][y]%;%char[0][x]%H%ESC%[38;2;184;20;184m%snake[cha][2]%"
:START
SETLOCAL
"%~F0" CONTROL >"%temp%\%~n0_signal.txt" | "%~F0" GAME <"%temp%\%~n0_signal.txt"
ENDLOCAL
GOTO :START
:GAME
FOR /L %%# in () DO (
SET /P "input="
SET /A "frames+=1"
IF !pel[x]! EQU 0 (
SET /A "pel[x]=!RANDOM! * ((%map[width]% - 1) - 2 + 1) / 32768 + 2", "pel[y]=!RANDOM! * ((%map[height]% - 1) - 2 + 1) / 32768 + 2"
SET "pel[disp]=%ESC%[!pel[y]!;!pel[x]!H%ESC%[38;2;50;168;82m■"
)
IF defined input (
FOR %%A in (!input!) DO (
IF not "!input[cur]!" == "!mov[%%A]!" (
SET "input[new]=1"
)
SET "input[cur]=!mov[%%A]!"
)
)
(SET /A "1/((((~(0-(frames %% snake[speed]))>>31)&1)&((~((frames %% snake[speed])-0)>>31)&1))|input[new])" 2>NUL) && (
SET /A "d[x]=char[0][x]","d[y]=char[0][y]","d[!input[cur]!","input[new]=0"
IF !d[x]! LSS %map[width]% ( IF !d[x]! GTR 1 (
IF !d[y]! LSS %map[height]% ( IF !d[y]! GTR 1 (
SET "snake[disp]="
SET /A "d[shift][x]=char[0][x]=d[x]","d[shift][y]=char[0][y]=d[y]"
IF "!pel[x]!;!pel[y]!" == "!d[x]!;!d[y]!" (
SET /A "pel[x]=0","snake[mass]+=1"
)
IF !snake[mass]! NEQ 1 (
FOR %%Q in (".!d[x]!;!d[y]!.") DO (
IF not "!snake[bou]!" == "!snake[bou]:%%~Q=!" (
%exit%
)
)
)
SET "snake[bou]="
FOR /L %%M in (1, 1, !snake[mass]!) DO (
SET "snake[bou]=!snake[bou]!.!char[%%M][x]!;!char[%%M][y]!"
SET /A "d[save][x]=char[%%M][x]","d[save][y]=char[%%M][y]", "char[%%M][x]=d[shift][x]","char[%%M][y]=d[shift][y]", "d[shift][x]=d[save][x]","d[shift][y]=d[save][y]","d[disp]=%%M %% 2"
IF !d[disp]! EQU 0 (
SET "snake[disp]=!snake[disp]!%ESC%[!char[%%M][y]!;!char[%%M][x]!H%ESC%[38;2;105;78;148m%snake[cha][1]%"
) else (
SET "snake[disp]=!snake[disp]!%ESC%[!char[%%M][y]!;!char[%%M][x]!H%ESC%[38;2;184;20;184m%snake[cha][2]%"
)
)
SET "snake[bou]=!snake[bou]!."
) else (%exit%)) else (%exit%)
) else (%exit%)) else (%exit%)
)
ECHO %ESC%[2J%ESC%[1;1H%disp[map]%!pel[disp]!!snake[disp]!%ESC%[38;2;255;255;255m%ESC%[%map[height]%;1H%ESC%[BScore : !snake[mass]!%ESC%[1G%ESC%[BUse WASD to move
)
:MAKEMAP <width> <height>
SETLOCAL
SET "disp[border]="
FOR /L %%W in (1, 1, %1) DO (
SET "disp[border]=!disp[border]!█"
)
SET /A "width[adj]=%1 - 2","height[adj]=%2 - 1"
SET "disp[map]=%disp[border]%#%ESC%[B%ESC%[%1D%disp[border]%"
FOR /L %%H in (2, 1, %height[adj]%) DO (
SET "disp[map]=!disp[map]:#=%ESC%[B%ESC%[%1D█%ESC%[%width[adj]%C█#!"
)
SET "disp[map]=%disp[map]:#=%"
ENDLOCAL&SET "disp[map]=%ESC%[38;2;148;194;224m%disp[map]%"&SET "disp[kill]=%ESC%[38;2;41;100;138m%disp[map]:█=X%"
GOTO :EOF
:CONTROL
FOR /L %%C in () do (
FOR /F "tokens=*" %%A in ('CHOICE /C:WASD /N') DO (
IF exist "%~dpn0.quit" (
DEL "%~dpn0.quit"
EXIT
)
<NUL SET /P ".=%%A"
)
)
GOTO :EOFSince it relies on VT100 sequences, it's Windows 10 only.
Have fun,
Lowsun
r/Batch • u/Outline227 • Oct 22 '24
No more Notepad or Notepad++ This is an IDE made by me to edit batch scripts and has some features that Notepad++ doesn't have like turn PowerShell code to one line and run in batch Link(Pre Release and buggy): https://outline227.itch.io/cse-console-script-editor also CSE stands
r/Batch • u/OzzyOPorosis • May 18 '21
Show 'n Tell Minesweeper in Batch
This is by far my most difficult project yet, one I can only describe as the culmination of several weeks of trying to trick cmd into doing things it should already be able to do. This is still a work in progress, but this is the closest I've come to something playable yet. I couldn't have done this without the help of Grub4K and several other people who've been doing this for a lot longer than I have.
DISCLAIMER: There is currently a bug that occurs when switching from a larger board to a smaller one, because array values are not reset unless they are used in the next game, which causes a conflict with the zero-chaining on the south and east sides of the board. If you want to switch from a large board to a small one, it is advised you close and reopen the script.
EDIT: This post was made on May 18, 2021. Today, January 17, 2022, per the request of u/XaaRi_, it has finally been updated with a functioning but incomplete implementation of flags with the E button.
@echo off
setlocal enabledelayedexpansion
for /f "delims=" %%g in ('forfiles /p "%~dp0." /m "%~nx0" /c "cmd /c echo(0x1B"') do set "esc=%%g"
echo %esc%[?25l
(set lf=^
%=%
)
set game[1]="height=9,width=9,mines=10"
set game[2]="height=16,width=16,mines=40"
set game[3]="height=16,width=30,mines=99"
set "zero=0"
set "move[1]=x l zero height -1"
set "move[2]=y l zero width -1"
set "move[3]=x g height zero 1"
set "move[4]=y g width zero 1"
set "count=0"
for %%g in (30 94 92 91 34 31 96 97 37) do (
set "c[!count!]=%esc%[%%gm!count!%esc%[0m"
set /a "count+=1"
)
set "c[-]=%esc%[7;31mX%esc%[0m"
rem Gamemode Selector
:a
cls
echo 1^) Beginner!lf!2^) Intermediate!lf!3^) Expert!lf!4^) Exit
choice /c 1234 /n >nul
if !errorlevel! equ 4 exit
set /a "!game[%errorlevel%]!"
set /a "area=(width*height)-1"
set /a "x=0,y=0,z=1"
set "string0=#"
set "string1=#"
rem Preprocessor
set "row=^^^!b^!h^!`!width!^^^!"
set /a "height-=1"
for /l %%g in (0,1,!height!) do (
for /l %%h in (0,1,!width!) do set "b%%g`%%h= "
)
set /a "width-=1"
for /l %%g in (0,1,!height!) do (
for /l %%h in (0,1,!width!) do (
set "a[%%g`%%h]=0"
set "d%%g`%%h=%esc%[90m?%esc%[0m"
set "string0=!string0!%%g`%%h#"
)
)
set /a "mines-=1"
for /l %%g in (!width!,-1,0) do set "row=^^^!b^!h^!`%%g^^^!^^^!d^!h^!`%%g^^^!!row!"
cls
:b
call :board
choice /c wasdq /n >nul
if "!errorlevel!" neq "5" (
call :move !move[%errorlevel%]!
goto b
)
rem Digitizer
set /a "win_con=area-mines"
for %%g in (0 1 2) do set "digit%%g=!area:~%%g,1!"
rem Excluder
for %%g in (-1 0 1) do (
for %%h in (-1 0 1) do (
set /a "m=x+%%g,n=y+%%h"
if !m! geq 0 (
if !m! leq !height! (
if !n! geq 0 (
if !n! leq !width! (
set /a "area-=1"
for %%i in ("!m!`!n!") do set "string0=!string0:#%%~i#=#!"
)
)
)
)
)
)
rem Sets h array, improvement possible
set /a "digit0-=1"
for /l %%g in (0,1,!digit0!) do (
for /l %%h in (0,1,9) do (
for /l %%i in (0,1,9) do (
for /f "tokens=1 delims=#" %%j in ("!string0!") do (
set "h[%%g%%h%%i]=%%~j"
set "string0=!string0:#%%~j#=#!"
set "string1=!string1!%%g%%h%%i#"
)
)
)
)
set /a "digit0+=1,digit1-=1"
for /l %%g in (0,1,!digit1!) do (
for /l %%h in (0,1,9) do (
for /f "tokens=1 delims=#" %%i in ("!string0!") do (
set "h[!digit0!%%g%%h]=%%~i"
set "string0=!string0:#%%~i#=#!"
set "string1=!string1!!digit0!%%g%%h#"
)
)
)
set /a "digit1+=1"
for /l %%g in (0,1,!digit2!) do (
for /f "tokens=1 delims=#" %%h in ("!string0!") do (
set "h[!digit0!!digit1!%%g]=%%~h"
set "string0=!string0:#%%~h#=#!"
set "string1=!string1!!digit0!!digit1!%%g#"
)
)
rem Randomizer and Incrementer
set "string0="
for /l %%g in (0,1,!mines!) do (
set /a "rand=4*(!random! %% !area!)+1, area-=1"
for %%h in (!rand!) do (
for /f %%i in ("!string1:~%%h,3!") do (
set "a[!h[%%~i]!]=-10"
set "string1=!string1:#%%~i#=#!"
set "string0=!string0!!h[%%i]! "
for /f "tokens=1,2 delims=`" %%j in ("!h[%%i]!") do (
for %%l in (-1 0 1) do (
for %%m in (-1 0 1) do (
set /a "m=%%j+%%l,n=%%k+%%m"
if !m! geq 0 (
if !m! leq !height! (
if !n! geq 0 (
if !n! leq !width! set /a "a[!m!`!n!]+=1"
)
)
)
)
)
)
)
)
)
rem Colorizer
for /l %%g in (0,1,!height!) do (
for /l %%h in (0,1,!width!) do (
for /f %%i in ("!a[%%g`%%h]:~0,1!") do set "a[%%g`%%h]=!c[%%i]!"
)
)
set "list=#!x!`!y!#"
set "done=#"
call :zero_chaining
:main
call :board
choice /c wasdqe /n >nul
if !errorlevel! leq 4 (
call :move !move[%errorlevel%]!
) else if !errorlevel! equ 5 (
call :dig
) else call :flag
goto main
:move
if !%1! %2eq !%3! (
set "%1=!%4!"
) else set /a "%1+=%5"
set /a "z=y+1"
exit /b
rem Improvement possible
:dig
for /f %%g in ("!x!`!y!") do (
if "!d%%~g:~5,1!" equ "?" (
if "!a[%%~g]:~7,1!" neq "X" (
if "!a[%%~g]:~5,1!" equ "0" (
set "list=#!x!`!y!#"
call :zero_chaining
) else (
set "d%%~g=!a[%%~g]!"
set /a "win_con-=1"
)
if !win_con! equ 0 (
call :board
echo You win
choice /c q /n >nul
goto a
)
) else (
for %%h in (!string0!) do (
set "d%%h=!a[%%h]!"
)
call :board
echo You lose
choice /c q /n >nul
goto a
)
)
)
exit /b
:flag
for /f %%g in ("!x!`!y!") do (
if "!d%%~g:~5,1!" equ "?" (
set "d%%g=P"
) else if "!d%%g!" equ "P" (
set "d%%g=%esc%[90m?%esc%[0m"
)
)
exit /b
:zero_chaining
for /f "tokens=1 delims=#" %%g in ("!list!") do (
set "list=!list:#%%~g#=#!"
set "done=!done!%%g#"
for /f "tokens=1,2 delims=`" %%h in ("%%~g") do (
for %%j in (-1 0 1) do (
for %%k in (-1 0 1) do (
set /a "m=%%h+%%j,n=%%i+%%k"
for %%l in ("!m!`!n!") do (
if !m! geq 0 (
if !m! leq !height! (
if !n! geq 0 (
if !n! leq !width! (
if "!d%%~l:~5,1!" equ "?" (
set "d%%~l=!a[%%~l]!"
set /a "win_con-=1"
if "!a[%%~l]:~5,1!" equ "0" (
if "!list:#%%~l#=#!" equ "!list!" (
if "!done:#%%~l#=#!" equ "!done!" set "list=!list!%%~l#"
)
)
)
)
)
)
)
)
)
)
)
)
if "!list:#=!" neq "" goto :zero_chaining
exit /b
:board
set "b!x!`!y!=["
set "b!x!`!z!=]"
set "board="
for /l %%g in (0,1,!height!) do (
set "h=%%g"
set "board=!board!%row%^!lf^!"
)
echo %esc%[1;1H%board%
set "b!x!`!y!= "
set "b!x!`!z!= "
exit /bPlease let me know if you happen to come across any bugs. I will continue to improve upon it and add new features.
r/Batch • u/thelowsunoverthemoon • May 05 '21
Show 'n Tell Graph.bat : a utility script to generate Bar Graphs
I don't think anyone's ever going to use this, but this seemed like a fun challenge in Batch. Given a file, it will generate a bar graph and put it into the variable "final". For example:
CALL GRAPH "input.txt" /X 1 /Y 2 /C █ /A 3 /YS 5 /W 1 /D 2 /NS 3Will take the data from "input.txt", make a graph at position 1;2 using █ characters, divide the data by 3 with a Y scale of 5, with bars of width 1 and distance 2, and a Y offset by 3. Here are all the options. Each has a default, so you don't have to specify each one.
The first argument is always the file name, the rest can be put in any order.
X is X coordinate (default 1)
Y is Y coordinate (default 1)
D is distance between bars (starts from 0) (default 1)
C is display char (default #)
A is data adjust, ie if it's 3 it's divide each point by 3 (default 1)
W is bar length (starts from 0) (default 1)
XR is start of X scale (default 1)
XS is X scale factor (default 1)
YR is start of Y scale (default 1)
YS is Y scale factor (default 1)
NS is the offset for the Y scale (default 2)
First, save this script into graph.bat.
SETLOCAL ENABLEDELAYEDEXPANSION
SET "param=%*"
SET "disp="&SET "disp[x]="&SET "disp[y]="&SET "final="
SET "param[C]=#"
SET /A "max=dif=param[num]=cur=0", "param[X]=param[NS]=param[Y]=param[D]=param[A]=param[W]=param[XR]=param[XS]=param[YR]=param[YS]=1", "param[NS]=2"
(ECHO %param:/=&SET /A "param[num]+=1"&SET param[!param[num]!]=%)>NUL
FOR /L %%P in (1, 1, %param[num]%) DO (
FOR /F "tokens=1-2 delims= " %%G in ("!param[%%P]!") DO (
IF defined param[%%G] (
SET "param[%%G]=%%H"
) else (
ECHO Invalid Switch /%%G
GOTO :EOF
)
)
)
IF %param[D]% NEQ 2 (
SET /A "param[D]-=1"
)
FOR /F %%Q in (%~1) DO (
SET /A "num=%%Q / param[A]", "cur+=1", "scale[x]=((cur - 1) * param[XS]) + param[XR]"
IF !num! GTR !max! (
SET /A "dif=num - max"
FOR /L %%G in (1, 1, !dif!) DO (
SET /A "scale[ycur]+=1", "scale[y]=((scale[ycur] - 1) * param[YS]) + param[YR]"
SET "disp=!disp!%ESC%[D%ESC%[A%param[C]%"
SET "disp[y]=!disp[y]!%ESC%[%param[X]%G%ESC%[A!scale[y]!"
)
SET "add=!disp!"
SET "max=!num!"
) else IF !num! EQU 0 (
SET "add=%ESC%[A"
) else (
SET /A "dif=(max - num) * 7"
IF !dif! EQU 0 (
SET "add=!disp!"
) else (
FOR %%L in (!dif!) DO (
SET "add=!disp:~0,-%%L!"
)
)
)
FOR /L %%G in (1, 1, %param[W]%) DO (
SET "final=!final!!add!%ESC%[C%ESC%[!num!B"
)
SET "final=!final!!width[disp]!%ESC%[%param[D]%C"
IF %param[D]% LSS 2 (
SET /A "scale[num]=((cur - 1) * (param[W] + param[D] + 1)) + param[X] + param[NS]"
) else (
SET /A "scale[num]=((cur - 1) * (param[W] + param[D])) + param[X] + param[NS]"
)
SET "disp[x]=!disp[x]!%ESC%[!scale[num]!G!scale[x]!"
)
ENDLOCAL&SET "final=%ESC%[%param[Y]%;%param[X]%H%ESC%[%max%B%disp[y]%%ESC%[%max%B%ESC%[%param[NS]%G%ESC%[2C%final%%disp[x]%"This script is decently fast and only needs one pass through the data. To generate the bars, it takes the maximum bar length and subtracts/adds to it, so it doesn't iterate again for each bar. And all you have to do is CALL GRAPH with your parameters. You must also define %ESC% in your code as the escape character. For example, here's a sample script:
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
MODE 140, 30
FOR /F %%A in ('ECHO PROMPT $E^| CMD') DO SET "ESC=%%A"
(CHCP 65001)>NUL
CALL GRAPH "input.txt" /X 1 /Y 2 /C █ /A 3 /YS 5 /W 1 /D 2 /NS 3
ECHO %ESC%[2J%ESC%[4mTemperature vs. Day%ESC%[24m%final%
PAUSE>NUL
EXIT /BThis generates https://imgur.com/0JCkfSj
Have fun,
Lowsun
r/Batch • u/thelowsunoverthemoon • Apr 10 '21
Show 'n Tell Easy String Sorting in Batch
Sorting strings is typically a painful task in Batch, but not with the SORT command. With the help of macros, you can make string sorting look very neat & tidy, almost like .filter methods in other programming languages. This is mostly syntactic sugar, but since it's only a simple variable using string substitution, I doubt there's going to be a measurable performance hit. Here they are:
SET "sort[fwd]=(FOR %%S in (%%#%%) DO @ECHO %%S) ^| SORT"
SET "sort[rev]=(FOR %%S in (%%#%%) DO @ECHO %%S) ^| SORT /R"
SET "filter[fwd]=(FOR %%F in (%%#%%) DO @ECHO %%F) ^| SORT /UNIQ"
SET "filter[rev]=(FOR %%F in (%%#%%) DO @ECHO %%F) ^| SORT /UNIQ /R"Given an array, all you have to do is "substitute" them in. For example:
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET "sort[rev]=(FOR %%S in (%%#%%) DO @ECHO %%S) ^| SORT /R"
SET "array=hello bye zero cool zack well this this cool augment bye"
%sort[rev]:#=array%
PAUSE
EXIT /BWill sort the contents of array alphabetically reversed. All you have to do is copy and paste the ones you're using into your script. This is what each one does:
sort[fwd] sorts the array alphabetically
sort[rev] sorts the array alphabetically reversed
filter[fwd] filters out the unique values of the array, then sorts alphabetically
filter[rev] filters out the unique values of the array, then sorts alphabetically reversed
But what happens if you want to put the output into a file? You can either redirect the entire command
(%filter[rev]:#=array%)>filtered.txtOr add the /O switch at the end
%filter[rev]:#=array% /O filtered.txtHow about if you want to do something to the sorted values? Lets say if you wanted to create variables for each value. All you have to do is escape the closing parenthesis using a caret. Ie here are the FOR /F "loop" versions:
SET "lsort[fwd]=(FOR %%S in (%%#%%^) DO @ECHO %%S^) ^| SORT"
SET "lsort[rev]=(FOR %%S in (%%#%%^) DO @ECHO %%S^) ^| SORT /R"
SET "lfilter[fwd]=(FOR %%F in (%%#%%^) DO @ECHO %%F^) ^| SORT /UNIQ"
SET "lfilter[rev]=(FOR %%F in (%%#%%^) DO @ECHO %%F^) ^| SORT /UNIQ /R"Example use:
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET "lfilter[rev]=(FOR %%F in (%%#%%^) DO @ECHO %%F^) ^| SORT /UNIQ /R"
SET "num=0"
SET "array=hello bye zero cool zack well this this cool augment bye"
FOR /F %%Q in ('%lfilter[rev]:#=array%') DO (
SET "array[!num!]=%%Q"
SET /A "num+=1"
)
SET array
PAUSE
EXIT /BCreates numbered variables for each sorted word. Here's a script that showcases each of the (non loop version) macros:
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET "sort[fwd]=(FOR %%S in (%%#%%) DO @ECHO %%S) ^| SORT"
SET "sort[rev]=(FOR %%S in (%%#%%) DO @ECHO %%S) ^| SORT /R"
SET "filter[fwd]=(FOR %%F in (%%#%%) DO @ECHO %%F) ^| SORT /UNIQ"
SET "filter[rev]=(FOR %%F in (%%#%%) DO @ECHO %%F) ^| SORT /UNIQ /R"
SET "array=hello bye zero cool zack well this this cool augment bye"
ECHO Original
FOR %%Q in (%array%) DO (
ECHO %%Q
)
ECHO/
ECHO Sorted Normal
%sort[fwd]:#=array%
ECHO/
ECHO Sorted Reversed
%sort[rev]:#=array%
ECHO/
ECHO Filtered Normal
%filter[fwd]:#=array%
ECHO/
ECHO Filtered Unique
%filter[rev]:#=array%
ECHO/
PAUSE
EXIT /BHave fun,
Lowsun
r/Batch • u/[deleted] • Sep 14 '19
ExeToBat - A tool to embed files in batch
What
is a project written in C# that aim towards embedding any amount of files into a batch file which will extract them on runtime. I made it and I'm posting it here in hope that it might help you in your future batch projects.
Why
Have you ever wanted to have one file and one file only for your batch project? Me too! This project does exactly that. It will allow you to put all your files into one simple batch file that extracts them at runtime. If you have ever used a self-extracting 7zip executable, this is the equivalent to it - in batch. It's the counterpart to the various "BatToExe" generators, which would embed your batch file into an executable.
How
ExeToBat converts all your files into a Base64 string and puts them into a bat file, along with a command to convert them back. Using certutil, which comes with all windows installations, it will convert your Base64 string back into a file and even run it for you, if desired. It also splits your strings into chunks to fit the filestream size of a "echo string > file" command, leading to maximum extraction speed.
Where
You can download a release of the project on the github. If you don't trust me, it's open source and you can build it yourself, or even read the source code if you like.
Excuse me?
The app has several options ready for you.
You can add entire folders for embedment for easy usage. Each file will be extracted in the order you want it to. It can be run after extraction, the extactor batch file can wait for it to complete the run and it can even delete it after running if desired. If you are familiar with batch yourself, you can even modify the extracting batch file however you like to adjust it to your needs.
Nobody Asked these Questions (NAQ)
How do I use this?
The app runs in a console. You select the menu entries by typing their corresponding number.
You want to generate a new file?
First use 1 to enter the add files screen. Use 0 to add a new file or directory.
After youre done adding files, go back to the main menu with q and use the second option generate with 2. The app will then generate your batch file in the same directory as it resides in.
How do I make this work with my own batch code?
The generated batch file is normal batch code and you can append to it or alter it how you like. However, I recommend putting your own code into a seperate batch file and then adding it to the embedded files as the last file and check the run option. This is also the intended usecase for this app. It will extract the files needed for your batch file and then run it, making it a one-file-batch-thing. I also recomnmend putting all your project files into one folder and then just adding that folder to the files for embedment.
Is this a virus?
No. This application does nothing malicious on your computer and you can read the soure code and compile it on your own machine to convince yourself.
I want feature abc or found bug xyz
I will fix bugs in this project and add new features if I got the time and there is demand for it. You are also welcome to open an issue or make a pull request if you have added the feature yourself.
Thank you for reading. I hope you like my project or give it a try. If anything is unclear, just ask in a reply or DMs.
r/Batch • u/Scared_Confection980 • 22d ago
Show 'n Tell A batch Pixel Editor compatible with any code
I updated a recent batch pixel Editor project and I said that I'd make it compatible with any batch code
So here it is, and with more options
You just need to write: call BPE_myproject.bat draw
Make sure that your image is in the same folder as your project
https://github.com/CodeBreaker-cmd/Batch-Pixel-Editor-/releases