Task Automation...


Home     Sitemap

www.diy-computer-repair.net logo

Ok, How Do You Write A Batch File Or CMD File?

To write a batch file do you need to be a geek or a nerd? Hummmm???

These files are a plain text file, you need to use an editor that does not format the text such as notepad.exe for Windows.

A word processor will only cause you problems when the file runs because it adds special formatting and characters to the file. The same for wordpad.exe for Windows unless you use the "Save as type:" and that type is "Text Document - MS-DOS Format".

To write a batch file: each line of a batch file can only have one command, that command however can have different options or "switches" added to the command.

If you are write a batch file that is one of a kind that will be used on one computer you don't have to worry about the path to the program the command is being issued for if the program is in the path statement of the environmental statements.

To be on the safe side always add the path to the program you are issuing the command for such as:

C:\Windows\System32\ntbackup.exe  (This is the built in backup program for Windows XP)

After the program run command you would add any special operations or options that you want the command to run.

Such as:

D:\apps\special\robocopy.exe D:\Business\ "H:\special files\Business" *.* /E /R:2 /W:5 /Z /XF

Each part of this command tells robocopy.exe that I want it to copy files from one directory/folder to another directory/folder, the switches tells robocopy.exe what parameters to look for on each file and when to copy the file or not.

Notice the quote marks around "H:\special files\Business" this is because "special files" has a space between the two words, this command will not run with DOS, DOS does not recognize spaces. Only higher level Operating Systems file management systems see a space as part of a file path.

Write a batch file instructions:

As you write a batch file or cmd file keep in mind that some commands can be destructive, if you think that a command may delete files test the command first on your temp directory or a special directory that you have made with dummy or useless files before turning it lose on your computer!

You need this in your IT Tool Box! Get yours today...

Troubleshoot, repair, maintain, upgrade & secure...

    With this!

If you are unfamiliar with a program use the help file to find out what can or can not be done with the program, some programs help files are very terse in the syntax (syntax is the wording of the command, as in the example above the *.* means that robocopy.exe will copy all files, this will also over write older files of the same name in the target directory).

Now that you have a batch or cmd file you need to name it, if you are using Windows NT or newer then name the file with the .cmd extension if you are going to use it on an older version of Windows, DOS, or Linux then name it with the .bat extension. (I don't remember what the exertion for a MAC OS would be).

Once you have saved your batch file your next step is to test it, once it works the way you want then finalize the file.

If you want to watch your batch file run you can use what is called a 'pause' statement, it will stop the batch file process after the command has run and wait for you to press 'enter' to run the next command such as:

  • Ping computera
  • Pause
  • Ping computerb
  • Pause

And so on through the batch file.

Once your testing is compete remove the pause command or you will have to press enter after each command when you want to use it unless you want to see the results.

If you have some old batch/cmd files do you remember what they were made for?

You could run it, then again it may be a destructive file and that might not be a good idea.

Or you could open it with a plain text editor and look at the commands, still don't remember what it does?

That is where documentation comes in. When you write a batch file it can document the batch/cmd file when you write it by using REM statements.

A REM (REMember - a hold over from Unix) statement isn't executed by the command line (DOS or CMD in Windows) it skips over the line.

Such as:

  • REM - Created 01/01/95 by Monte Russell
  • REM - This batch file starts the game ACES Over The Pacific
  • REM - Sets the environment for the Sound Blaster
  • REM - Changes to the RAM Drive
  • REM - Creates the ACES directory
  • REM - Copies all the files
  • REM - Starts ACES!

There are a lot of things a batch file can do for you that is either mundane or takes longer to type the command in than it does to run.

You can even write a batch file or cmd file to restart a remote computer on a certain day at a certain time, stop or start services, loads of fun things ... :)

What would you use a batch or cmd file for?

Emergency Repair
isk (ERD) - Will Yours Work?

Repair Disk

Custom made for you...

You keyboard isn't thirsty, and it doesn't need calcium. Milk and other liquids will ruin a keyaboard!

This Web
Site is a
labor of Love
But Love
doesn't pay
the bills!

Please chip in $5 to keep it live...

Need A Checklist?

Need A Repair Manual?

    Page copy protected against web site content infringement by Copyscape

You can:

Return to
previous page:





Thank you for visiting my web site, and please come back again.

This website is not intended for children under the age of 18

Author of this web site: Monte Russell

FTC Endorsement Rules
All testimonials on the DIY Computer Repair web site are from customers who were not paid to comment on any products!

The Flag of The United States of America!   Proudly Made in The U. S. A.

Copyright and Registered to www.diy-computer-repair.net, all thieves will be prosecuted to the fullest extent of international law!www.diy-computer-repair.net

From the Desert South West ~ Arizona, U. S. A.
Copyright DIY-Computer-Repair.Com 2006-2016


"You found this web site through:"

Active Search Results

Return to top of Write A Batch File

Write a batch file and let it do the work for you...

Home    About    Sitemap
Fix It Blog!

From the Desert South West ~ Arizona, USA
Copyright www.diy-computer-repair.net 2006-2015