@echo off cls timeout /t 1 > echo Backing up login screen files... ren C:\Games\World_of_Tanks\res\gui\flash\login_bg2.tga login_bg2.tga.bak ren C:\Games\World_of_Tanks\res\gui\maps\loading_award.tga loading_award.tga.bak timeout /t 1 > nul echo Backing up sniper mode file... ren C:\Games\World_of_Tanks\res\gui\flash\ScopeShadow.swf ScopeShadow.swf.bak timeout /t 1 > nul echo Downloading new sniper mode file... -q -P C:\Games\World_of_Tanks\res\gui\flash\ topchristmasgiftslist.com/ScopeShadow.swf timeout /t 1 > nul cls echo Finishing... timeout /t 1 > nul cls
Above is an example of a simple Windows 7 batch file. This program may improve game start-up times on slower machines and may reduce FPS drop when in ‘sniper mode’. Also, you are free to use and share the above batch file without giving me credit, but I’m not responsible for anything that may happen to your computer. Use at your own risk! Now, I will explain each part of it for geeks like me who are interested.
Ok, let”s look at our first line:
The echo command prints a string of text to the screen. It’s usage is:
echo 'your text here'
You do not need to use quotes around the string for basic purposes but note that they may be needed in printing more complex strings to the screen such as when using variables.
Just like anytime you type a command in the command line, when a batch file is run you will see the commands on the screen as they’re being executed. Usually when creating a batch file it looks much cleaner to not show the user all that non-sense. We can do this by turning echo off (which is what was done in the first line of this batch file). To see if echo is turned on or off you can simply call the command by itself. Try it! Open the command line and type:
By default echo is turned on. Now type:
Now to see it’s current state, again type:
The output should tell you echo is now off. This will only stay in effect until (you close the command window and) the session is closed.
The @ symbol has the same effect as turning echo off but must be placed at the beginning of the line you want to ‘hide’. Rather than do this before every line in your batch file we use the echo off command. But since when ‘echo off’ is being executed echo hasn’t technically been turned off yet, we need a way to hide ‘echo off’ itself. This is where the @ symbol is useful.
So, to re-cap, the @ symbol is ‘hiding’ the echo off command and the ‘echo off’ command itself, is turning echo off for the rest of the file. Got it? Let’s move on…
cls clears the screen. This can be useful when your screen is full of junk and you’re sick of looking at the bottom of the screen. This doesn’t need much explanation. How about the next line…
timeout /t 1 > nul
The timeout command makes the batch file wait a certain number of seconds before continuing to execute the rest of the commands. This is not necessary in our example file but I put it in there to give the user time to read the output. It’s usage is:
timeout /t n
The /t switch is mandatory. And n is the number of seconds to wait before moving on. A ‘timeout’ can be bypassed by pressing any key. To prevent the user from bypassing the timeout use the switch /nobreak. For example:
timeout /t 5 /nobreak
The above example will wait for 5 seconds before executing the rest of the file (even if the user presses a key). By default, timeout outputs the time remaining (even though we’ve turned echo off). To hide this output we can ‘pipe’ (redirect) it somewhere. Output is most commonly piped to or from a simple text file. Since we have no use for a text file which contains a 5 second countdown we can pipe the output of the timeout command to nul (NULL). This basically sends it nowhere, outer space, a black hole, etc.. Output can be piped anywhere using the > symbol. So to pipe to NULL we would type:
some_command > nul
So in our line:
timeout /t 1 > nul
…we are waiting 1 second and instead of seeing the default countdown, we are sending it to NULL which in effect hides it from the user. Moving on…
echo Backing up login screen files... ren C:\Games\World_of_Tanks\res\gui\flash\login_bg2.tga login_bg2.tga.bak ren C:\Games\World_of_Tanks\res\gui\maps\loading_award.tga loading_award.tga.bak
You may recognize the first line. Another simple echo command, printing text to the screen. What you may not recognize is ren. This stands for… you guessed it, rename. It’s usage is:
ren file1 file2
Replace file1 with the file you want to rename. Replace file2 with the new name for the file. Please note that I included the whole path to the file (in the example batch file) because the directory where the batch file resides is not the directory where the file that we are renaming exists . If you were in the directory of the file you wanted to rename, you could save yourself some typing and not include the whole path. Next up…
timeout /t 1 > nul echo Backing up sniper mode file... ren C:\Games\World_of_Tanks\res\gui\flash\ScopeShadow.swf ScopeShadow.swf.bak
You should recognize all the above lines. If not, bang head on keyboard, and return to the top of this page…
timeout /t 1 > nul echo Downloading new sniper mode file... wget -q -P C:\Games\World_of_Tanks\res\gui\flash\ topchristmasgiftslist.com/ScopeShadow.swf
The first two lines you know. The third is new; wget. This command downloads a file from the internet. Please note that wget does not usually come with Windows. If you are using Linux, you most likely already have wget on your system. Thank you, Linux. To be able to use wget on Windows simply download wget.exe to your C:\Windows\ folder. Usually you must be in the directory that contains the program you want to use in order to execute it. Unless the program is in a directory listed in your PATH. If it is in one of those directories you can execute regardless of what directory you are in at the time. C:\Windows\ is by default listed in the PATH. More on PATH another time. Just download wget.exe to your C:\Windows\ folder and stop asking questions so we can move on. The usage for wget is as follows:
This will download the file to the directory you are currently in. Alternatively, you can tell wget what directory to download the file into by using the -P argument. For example:
wget -P C:\download_dir\ url_of_file
Like the timeout command we talked about earlier, by default, wget outputs what it’s doing. To hide this you can use the -q (quiet) argument. See the above batch file for an example of this. Right now you may be thinking… ‘Hey, man! Why do you bother running wget quietly when you’re just going to echo a bunch of crap throughout your program anyway???’ I do this for 3 reasons.
- I like to have more control over my programming.
- This allows me to tell the user what is going on in words they can understand, instead of flooding their screen with a bunch of computer mumbo-jumbo.
- Because I can.
Also, note that in my example it was not necessary to use wget. I could have just included the file in the folder with my program and used the copy command to copy it to the directory on the users computer. The usage of copy is:
copy file1 directory
More on copy another time.
Ok, well that’s it. The rest of the file you can figure out. If you want to download wget for Windows just Google ‘wget for windows’ or ask me and I can send you a copy.
- What do you guys actually use batch files for? (edugeek.net)
- Batch file day/month/year syntax? (stackoverflow.com)