Welcome to the Call of Duty 4 Forums! Please REGISTER!
Hey there!
It looks like you're enjoying Call of Duty 4 Forums but haven't created an account yet. Why not take a minute to register for your own free account now? As a member you get free access to all of our forums and posts plus the ability to post your own messages, communicate directly with other members and much more. You also have the chance to win great prizes just for posting! Register now!
Already a member? Login at the top of this page to stop seeing this message.
Hello,and today I will be teaching you all how to create a batch file,run it and understanding the key parts in a batch file.
Step 1 : Creating the Batch File
Before we can start,we need to know how to create a batch file.
Go to your desktop--->Right Click--->New--->Text Document
This is where are gonna work,don't name the "New Text Document" just double click it and open it yourself,now you should have a blank notepad document.
Step 2 : Understanding Batch and what it can be used for
Batch can be used for both good and bad,bad because you can delete files and good because you can create your own programs to do certain functions.Please be careful when downloading or runnng any batch files,right click the batch file and go to "Edit" And see if there is anything unusual or weird about the text inside of it.
Step 3 : Batch commands ;setting up your batch file
These are some commonly known DOS commands(I take no credit for making these commands,I only use them):
The most common DOS commands in batch are del, cls, and echo(There are way more but I will not add them due to the fact i'm not too good with Batch and i'm just going over the basics)
Explaining the functions and uses of DOS commands
The del command is pretty easy to use among all of the others,it deletes a file(As i was explaining it can be used for bad so please check ALL Batch files BEFORE Running)
This is the del command syntax:
Code:
del [filename]
For example,if you wanted to delete a file called a:\Readme.txt the finished product would look like this:
Code:
del a:/Readme.txt
Now,I'm not sure if it is case sensitive but you can play around and try.
The CLS command is also very basic,it clears the screen.This is the syntax is uses:
Code:
cls
Pause is the command that stops the program and prompts you to "Press any key to continue..."
This is the syntax it uses:
Code:
pause
Echo is a DOS command that allows you to see what you're typing.In any Batch program the @ symbol means not to echo a line.So typing ECHO OFF will result in the user not being able to see the Batch program exucute.
To prevent it from echoing the ECHO OFF command,type the @ symbol in front of it.When you put all this information together you get:
Code:
@echo off
All good batch programs will most likely start off with the "@ECHO OFF"command usually followed by CLS
Important: If you use the @ECHO OFF command in your batch program, be sure to put ECHO ON at the end of the batch program or the user will think their computer is messed up when it actually isn't. The ECHO ON command looks like this:
Code:
echo on
Now for creating the Batch File
Remember that small tutorial in the beginning when you created the New text document? Well you're going to be needing it now,so open it if you haven't already.
Now,in your new text document type:
Code:
@echo off
cls
echo Hi, my name is %1
pause
echo This is the contents of this batch file:
pause
type anything.bat
Then save it in a file called anything.bat. The "%1" allows you to add data to your batch file from the command line. Whatever you type after the batch filename at the DOS prompt will replace the %1.
At DOS prompt, type
myname "YOURNAME HERE"
Below are some screenshots of my batchfile in action:
Here is an example of what you can do with the code I gave you earlier,this is what my finished product looks like:
Code:
@echo off
cls
echo Hi, my name is %1Brad and this is an operable batch program
pause
cls
echo I hoped you enjoyed my tutorial on creating and using the basics of batch!
pause
type anything.bat
Well,I hope you enjoyed the guide!
Leave feedback and opinions please
Keep all rude/negative comments/remarks to yourself please
__________________
Rank: 10th Prestige,55
Total Kills: 52,000+
Total Headshots: 12,000+
I'm back and i'm looking for a clan,add my gamertag:
FiBeR OpTiiX
Juggernaut & Martyrdom are like a Tampon,every pussy needs one.If you agree put this in your signature.
Payin' The Bills (Register to get rid of this
advertisement!)
only really have a useful function if you work in IT.
i've scripted a few batch files myself for modifying permissions on folder structures, deleting & recreating folder structures, adding printers to a users session on login, copying backups from one network location to another etc.
you can also use batch files to call external vbs scripts to run.
handy stuff to automate simple repetetive tasks
also not to be picky but shouldn't this go in "Software/programming" since it is programming lol
what the hell is a batch file. You could've described what one is before you started to give a tutorial. Is DOS what old computer games ran off of back in the day. Because I remember playing NBA LIVE 95 and it was a DOS program, I think, I could be wrong but am I right?
__________________
The only opinion that matters at the boards is mine.