Saturday, March 24, 2012

How to write a bat file

The basics are simple, you essentially open Notepad type in whatever command you want to call and save it with a .bat extension.


Anything written in the bat file will be called as a command line argument eg 


dir c:\windows

ECHO outputs to the console window and is the equivalent to trace in actionscript or puts in ruby
Having an @ symbol stops anything after it from appearing in the console window
So what does all this mean, well it means the first line of code we will want to turn ECHO off and also not show that line with:

@ECHO off 
dir c:\windows 

Save this as run.bat and double click it to run it. You will see it's gone in the blink of an eye, what we need is it to hang on a second so we can read it and for that we need to add a PAUSE.

@ECHO off 
dir c:\windows
PAUSE

Now when we run the bat file we see all the contents of the c:\windows directory listed out for us.

Another useful command when you are first playing with this stuff is REM, REM comments out a line of code but it will still appear unless you turn ECHO off.

There's tons of useful info here

No comments:

Post a Comment