Cool Batch Tricks - Part II

Hello guys,

        I'm back again with the 2nd part of Cool Batch Tricks. In this series, I present some cool Batch Files & try to explain how they work. If you still haven’t seen the first part of the series, Click Here.You should watch the first part as it will help you to understand the code.


So, Let’s start.   

Today, we will again learn two cool but very easy and programs. They are :-


1.    Folder Bomber

     This program creates folders with random names. You can set a limit or create unlimited folders (Can be used as a Virus, but IF SOMETHING WRONG HAPPENS DON’T BLAME ME)

Code:

@echo off
Title Folder Bomber
color a
:start
cls
echo.
echo.
echo NOTE : Folders will be bombed in a folder called bomb
echo.
echo.
echo.
echo.
echo Folder Bomber
echo.
echo.
echo Choose an Option??
echo 1. Limited
echo 2. Unlimited
set /p a=Enter Choice:
if %a%==1 goto limited
if %a%==2 goto unlimited
cls
echo Wrong Choice
pause
goto start

:unlimited
md bomb\%random%
cls
goto unlimited
pause

:Limited
set i=0
echo How many folders to bomb??
set /p b=Enter no. of Folders

:s
md bomb\%random%
set /a "i=i+1"
if %i%==%b% goto exit
goto s

:exit
echo %b% folders bombed successfully
pause>nul
exit







Output:



          I won’t be explaining the lines I already explained in previous posts.

          The 2nd line ‘Title Folder Bomber’ sets the Title to Folder Bomber in the Title Bar. The command’echo.’ Is used to print a blank line.
         
          The if condition checks that if value of a is equal to 1, if true, then it directs the interpreter to the ‘Limited’ Section. The same is for next if condition.
         
          The ‘cls’ command is used to clear the screen. The ‘md’ command means Make directory. It creates a new directory named ‘bomb’ & also creates a sub-directory of the value of random.

          In limited Section we set the value of variable ‘i’ to 0. Then we create a loop with a condition inside it. If the condition is matched then the interpreter jumps out of the loop, else it repeats the commands in the loop.

          We’ve used nul in front of pause with ‘>’, so pause won’t display any text when executed.

2.   Calculator

As the name suggests, this program is used to calculate the values of expressions entered.


Code:

@echo off
color a
Title Calculator
:Start
cls
echo -----------
echo Calculator
echo -----------
echo Enter the expression you want to calculate
set /p e=Expression :
set /a "x=%e%"
echo The answer is %x%
echo Do you want to calculate another expression ?
set /p y=Press NO to exit :
if %y%==No GOTO Exit
if %y%==NO GOTO Exit
if %y%==no GOTO Exit
GOTO start
pause
:Exit
echo Exitting Program...
pause
exit


Output:


       

          Here, we’ve used the set command with another parameter i.e ‘/a’. With this parameter, we can calculate the the value of an expression. We get the expression through the variable ‘e’ and set the output value of this expression to’x’. Then we print the variable ‘x’. Then we ask the user to repeat the process or not. Thus, it is so simple


Batch Files:                                              1.  Folder Bomber                               
                                                                  2.  Calculator


So, these were the two programs of this tutorial. If you like this post please support us by sharing the post. Don't Forget to visit our Facebook & Instagram pages, If you want to contact us, write us at Remedyhub11@gmail.com & don’t forget to subscribe.