Monday, May 23, 2011

«tHe MaK3inG oF B|Tch FiL3»

WhaT Is B|TcH FiLe

Batch 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.

Creating a b|tch 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. Additional information about doing this can be found on document CHDOS.
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:

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 is the case, you would either need to obtain the 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.
4. 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 is a test batch file
dir c:\windows

5. 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.
6. 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.

No comments:

Post a Comment