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.
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!
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).
Troubleshoot, repair, maintain, upgrade & secure...
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
- Ping computerb
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
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.
- 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!
- DEVICE=C:\SB\SB.SYS /I:5 /DMA:3
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?