PCSTATS     
[X]   Directory of
Guides & Reviews

Beginners Guides
Motherboards by Brand
Weekly Newsletter
Archived Newsletters

+70 MORE Beginner GUIDES....
Beginners Guides: Understanding and Creating Batch Files
Beginners Guides: Understanding and Creating Batch Files - PCSTATS
Batch files can save time by automating actions down to one simple click. A good understanding of what they are, how they work, and how to create your own, is crucial to today's IT force.
Filed under: Beginners Guides Published:  Author: 
External Mfg. Website: PCSTATS Apr 04 2011   M. Dowler  
Home > Reviews > Beginners Guides > PCSTATS

Batch file error levels and the goto command

When a command is executed in a batch file, in addition to any information it may display on the screen, it also returns an error level to the batch file itself. This error level is either errorlevel 0 (meaning no error occurred and the program worked correctly) or errorlevel 1 (an error occurred and that section of the batch file did not work correctly). For example, if you created a simple batch file to format a disk in your floppy (a:) drive like so:

@echo off
format a:

The format command in the batch file would return errorlevel 0 if there was a disk in the drive and it was formatted correctly, while if there was not, or the disk could not be formatted, it would return errorlevel1. By using these errorlevels and the GOTO command, you can set up your batch files to do different things depending on whether the commands in them succeed or fail. For example, you can use the IF command along with the errorlevel returned by the format command to let the user know whether the operation was successful or not:

@echo off
format a:
if errorlevel 1 goto error *go to the :error heading if there's an error in format
echo your disk formatted successfully *if format returned no error, show this message
goto end *go to the :end heading to finish the program
:error
echo an error occurred during formatting
:end
echo formatting finished

There's no way we could cover all the angles of batch files in a single guide, so we've got to stop here. If you've been following along, you should have picked up enough of the fundamentals and possibilities of batch file creation to start designing your own. Start with modifying the ones we made here to suit your own backup needs, then progress from there. Have fun!

Find out about this and many other reviews by joining the Weekly PCstats.com Newsletter today! Catch all of PCstats latest hardware reviews right here.

- Windows XP Service Pack 2
- Firewall Setup and Configuration
-Eliminating Spyware and Hijacker Software
- Diagnosing Bad Memory
- 101 Tips and Tweaks for WindowsXP
- Burning CDs and DVDs
- Optical Drives & Recording Formats
- Securing Your Wireless Network
- Little Known Features of WindowsXP
- Ergonomics & Computers
- Annual PC Checkup
- Installing WindowsXP
- Encryption and Online Privacy
- Home Networking and File Sharing
- Forgotten Passwords & Recovery Methods
- Preventing Data Theft from a Stolen Laptop
- Creating a Weblog / Blog
- Installing RAID on Desktop PCs
- RAM, Memory and Upgrading
- Ten Steps to a Secure PC
- Flashing A Motherboard BIOS
- Windows XP Safe Mode Explained
- Upgrading Win98 to Windows XP
- USB Memory Drive Projects
- 104 Great Tech Tips for Windows XP
- Unattended Windows 2000/XP Installations
- Linux Part 2: Installing a PC
- Understanding and Tweaking WindowsXP Services
- The Registry: Backups, Repairs, and Protection
- Diagnosing Bad Hard Drives
- Decrypting Document & Zipped File Passwords
- Spyware protection and Removal
- Wireless home networking
- Internet Connection Sharing
- Remote Access to Computers
- Hard Drive Data Recovery
- Firewalls and Internet Security
- Back up and Restore Data in WinXP
- Assembling Your Own PC
- VPNs and Internet Connection Security
- Legally Copying Software and Music
- Setting up a FTP Server in WinXP
- Creating MP3 Music Files
- Stopping Spam
- Cloning WindowsXP
- Browser Hijacking and How to Stop It
- Printer Sharing on a Home Network
- Converting Videotape Into Video Files
- Creating a WindowsXP Install CD with Service Pack 2
- Creating a Flashing a Video Card BIOS
- Making DVD Movies from Video Files
- Synchronizing Files and Folders
- Crash Recovery and the Blue Screen of Death
- Most Common Ways to Kill a PC
- WindowsXP Command Prompt
- Linux Part 1: Getting Familiar

< Previous Page © 2023 PCSTATS.com
Please respect the time and effort that went into creating each PCSTATS Beginners Guide, do not illegally copy. Thank you.
Beginners Guides Reviews...»

 

Contents of Article: PCSTATS
 Pg 1.  Beginners Guides: Understanding and Creating Batch Files
 Pg 2.  Creating a BATCH File
 Pg 3.  Preparing for your second batch file
 Pg 4.  Anatomy of a batch file
 Pg 5.  Third trial batch file: getting fancy
 Pg 6.  — Batch file error levels and the goto command

 
Hardware Sections 


 
PCSTATS Network Features Information About Us Contact
FrostyTech
PCSTATS Newsletter
Tech Glossary
Technology WebSite Listings
News Archives
(Review RSS Feed)
Site Map
PCstats Wallpaper
About Us
Privacy Policy
Advertise on PCSTATS

How's Our Driving?
© Copyright 1999-2023 www.pcstats.com All rights reserved. Privacy policy and Terms of Use.