How to Write Batch Files (with Pictures)1. To create a basic batch file in MS- DOS, follow the steps that give you an example of how to create a basic batch file. Open an MS- DOS command window or get to MS- DOS.
At the MS- DOS prompt, type: edit test. Note: This command is for windows XP and may not be available on other version of windows. If typed properly, you should now be in a blue screen.
One of the earliest batch files was the autoexec.bat, which is a boot batch file loaded each time the computer started MS-DOS. How to create a delay in a batch file. How to Write Batch Files. This opens Notepad, asking if you wish to create 'test.bat' which doesn't exist already, all at once. Say 'yes' and continue as before.
Within the screen, type: Pause. Dir c: \windows. Dir c: \windows\system. Once the above three lines have been typed in, click File and choose exit; when prompted to save, click "Yes." Users who do not have a mouse cursor can accomplish this same task by pressing ALT+F to access the file menu, then pressing "X" to exit, and pressing enter to save changes. Once you are back at the MS- DOS prompt, type: test and press enter.
This will execute the test. Because the first line is pause, you will first be prompted to press a key. Once you press a key the batch file will run line- by- line; in this case, listing the files in the windows and windows\system directories. A Windows user can still use the above MS- DOS steps if they wish to create a batch file. If, however, you're more comfortable using Microsoft Windows or your operating system, you can use any text editor, such as Notepad or Wordpad, to create your batch files, as long as the file extension ends with .
In the below example we use the Windows notepad to create a batch file. Type: notepad and press enter. Once notepad is open, type the below lines in the file or copy and paste the below lines into notepad. Hello this is a test batch file. Click File and click Save; browse to where you want to save the file. For the file name, type "test. Windows has a "Save as type" option, choose "All files", otherwise it will save as a text file.
An alternative to the above, is to simply type 'notepad test. This opens Notepad, asking if you wish to create "test. Say "yes" and continue as before. Once all of this has been done, click the Save button and exit Notepad. Now, to run the batch file, simply type 'test' at the command- line or double- click and run the file like any other Windows program. Once the batch file has completed running it will close the window automatically.