- Jun 11, 2012
- 114
Batch file ABCsBatch files allow MS-DOS and Microsoft Windows users to create a lists of commands to run in sequence once the batch file has been executed. For example, a batch file could be used to run frequently run commands, deleting a series of files, moving files, etc. A simple batch file does not require any special programming skills and can be done by users who have a basic understanding of MS-DOS commands.A good example of a batch file for someone who is more familiar with Windows or the MacOS is to think of a batch file as a shortcut in Windows or an icon on the MacOS. Much like a shortcut, batch files could be used to run one or more commands or programs through the command line.Another example of a very well known batch file is the autoexec.bat, which is a boot batch file loaded each time the computer boots into MS-DOS and early versions of Windows. This batch file contained all the necessary commands and programs used to run MS-DOS and Windows each time the computer booted.Creating a batch file
MS-DOS users
To create a basic batch file in MS-DOS, follow the below steps that give you an example of how to create a basic batch file.
1. Open an MS-DOS command window or get to MS-DOS.
2. At the MS-DOS prompt, type: edit test.bat and press enter.
3. If typed properly, you should now be in a blue screen. Within the screen, type:
pause
dir c:\windows
dir c:\windows\system
4. 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.
5. Once you are back at the MS-DOS prompt, type: test and press enter. This will execute the test.bat file and begin running the file. 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.
If you wish to add more lines to this batch file you would type "edit test.bat" to edit the file again.Additional information about the MS-DOS edit command can be found on our edit command page. Some versions of MS-DOS and bootable diskettes may not have the edit command; if this the case, you would either need to obtain the edit.com file to access this file or use the copy con command.
Microsoft Windows and other users
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 .bat. In the below example we use the Windows notepad to create a batch file.
1. Click Start
2. Click Run
3. 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.
@echo off
echo Hello this a test batch file
pause
dir c:\windows
4. Click File and click Save; browse to where you want to save the file. For the file name, type "test.bat", and if your version of Windows has a "Save as type" option, choose "All files", otherwise it will save as a text file. Once all of this has been done click the Save button and exit notepad.
5. Now, to run the batch file, double-click or run the file like any other program. Once the batch file has completed running it will close the window automatically.
Batch File Helping Codes
MS-DOS users
To create a basic batch file in MS-DOS, follow the below steps that give you an example of how to create a basic batch file.
1. Open an MS-DOS command window or get to MS-DOS.
2. At the MS-DOS prompt, type: edit test.bat and press enter.
3. If typed properly, you should now be in a blue screen. Within the screen, type:
pause
dir c:\windows
dir c:\windows\system
4. 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.
5. Once you are back at the MS-DOS prompt, type: test and press enter. This will execute the test.bat file and begin running the file. 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.
If you wish to add more lines to this batch file you would type "edit test.bat" to edit the file again.Additional information about the MS-DOS edit command can be found on our edit command page. Some versions of MS-DOS and bootable diskettes may not have the edit command; if this the case, you would either need to obtain the edit.com file to access this file or use the copy con command.
Microsoft Windows and other users
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 .bat. In the below example we use the Windows notepad to create a batch file.
1. Click Start
2. Click Run
3. 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.
@echo off
echo Hello this a test batch file
pause
dir c:\windows
4. Click File and click Save; browse to where you want to save the file. For the file name, type "test.bat", and if your version of Windows has a "Save as type" option, choose "All files", otherwise it will save as a text file. Once all of this has been done click the Save button and exit notepad.
5. Now, to run the batch file, double-click or run the file like any other program. Once the batch file has completed running it will close the window automatically.
Batch File Helping Codes