Jump to content

Recommended Posts

Posted
Ozxa.jpeg

Part One

 

I wrote this a while back on an old forum, and it was leeched and put on HF and other forums. This is my tut, but if you see it elsewhere don't say I leeched it.

 

Well, I see that you have decided to take part on this journey of batch coding. I am just going to let you know beforehand that some of the stuff after this can get annoying if you have errors in your code, so don't give up! Anyways, let's get on with the tutorial.

 

First you are going to want to open up a normal text file in notepad. Then you are going to want to type something like this:

wRL78.jpg

 

That "Echo" command is the best way to communicate to the person using your batch file. It will display a message on the screen with whatever you typed. Now you can go ahead and save by changing the .txt to a .bat, and making sure it is on "All Files" as the save option: lC81r.jpg

 

Now run your batch file, wherever you saved it. Did you see a flash on your screen? That was the batch file coming up and disappearing almost instantly. The reason for this is because there was no command to make it wait for the user to close it. What you are going to need to do is right click on the batch file and click on "Edit":

N5z1V.jpg

 

Now you are going to want to type the word "pause" on the line afterwards, like so: 59nHH.jpg

 

The command pause waits for the user to press a certain button or use a certain function (in this case, any key on the keyboard). Now you can save it again. Run your batch file again, and it should look something like this:

AGMRy.jpg

 

Oh gosh, another problem? Yes. This time the issue is that the batch program is displaying the directory of where the command is coming from. In my case, it is showing the path to the desktop, where I have the file saved. But there is a very easy fix to this. Open it up using the "Edit" option in the right click menu, and type "@echo off" a line BEFORE the "echo" command line: iuz63.jpg

 

This "@echo off" is the SINGLE MOST IMPORTANT COMMAND YOU WILL EVER USE IN A BATCH FILE EVER. Sorry about the all caps, I was just trying to get it through your head that it is the SINGLE MOST IMPORTANT COMMAND YOU WILL EVER USE IN A BATCH FILE EV.. fine, I'll stop now. There is a little more of an in-depth explanation I could give you here, but the easiest way to explain it is that it basically covers up that directory, so that you don't see the actual command being processed, and just the output. Alright, now that I am done explaining that to you, save your batch file and run it:

9rhFc.jpg

 

Success! You have made your first batch file. Doesn't matter at this point how complex it is, because at the end of this tutorial you'll be able to make a complex one yourself. On the next page, I will be talking about making your batch file wait a period of time, and also how to use user input to operate the commands you want.

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...