Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
Photo

Batch File Scripting - Beginner's Guide


  • Please log in to reply

#1
Ebsuru

Ebsuru

    Member

  • Member
  • PipPip
  • 39 posts
Hello everyone,

I thought I might share some of my knowledge with you all, so I decided to make this. In this tutorial you will be learning about the basics of batch file scripting. To write a batch file, all you need is notepad. So let's get started! :)

Start off by opening up notepad. Once you have done that, enter this:

@echo off

Add that to the first line. What this does is it stop file path info from being shown, it makes your batch file look a lot neater, just make sure you have that there. On the next line, we are going to set a title.

title MY TITLE

That's an example on how to set a title called "MY TITLE" just change that to what you want your title to be. On the next line, let's make our batch file say something! To do that, use the "echo" command. Type echo and then what you want it to say. So for example:
echo Hello World!

That would make it say "Hello World!" Now if we run our batch file right now, it would close automatically. Why? Well we forgot the pause command. The pause command stops the batch file from closing. It will display a message saying "Press any key to continue..." and then when the user presses a key, it moves on to the next line of code. So now, just add more echo and pause commands. You should have something like this now:

@echo off
title MY TITLE
echo Hello world! 
pause

Add more echo and pause commands now, my batch file looks like this:

@echo off
title MY TITLE
echo Hello World!
pause
echo Hi!
echo G2G
pause

Now it's time to actually run our batch file! But before we can do that, we need to save the file. Click File > Save As. Name it anything you want but at the end of the file name put in ".bat" to make it a batch file. Then for the "Save as type" select "All Files" not "Text Files"... this is very important. Now run the file you just made. Here is mine:

Posted Image

Congratulations on writing your first batch file! If you have any questions or if you have encountered a problem, feel free to contact me, I am willing to help. Thanks for reading this guide, I hope it taught you something.


Best Regards,

-Ebsuru
  • 0

Advertisements







Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP