Information on batch files
Quick links Batch file ABCs 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. 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 and/or programs through the command line. Another example of a very well known batch file is the autoexec.bat, which is a simple boot file loaded each time the computer is loaded on MS-DOS and early Windows computers. This batch file contained all the necessary commands and programs used to run MS-DOS and Windows each time the computer booted.
|
|
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.
If you wish to add more lines to this batch file you would simply 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 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.
Just like all MS-DOS commands, all batch file commands are not case sensitive. However, in the below listing we have listed all commands in all caps to help you identify what is a command and what is not.
Running different programs Below is a simple example of how you can implement the choice options into your batch files. Each line that is in red can be left out of the batch file. They have been included to help explain some of what the batch file means. Windows 2000 and Windows XP users will need to substitute the choice command with the set command; see our set command page for additional help and information with this command. @ECHO OFF How to start Windows files and other programs from a batch file To run Microsoft Windows programs or files use the START command. The below example would run Windows Notepad. START /MAX NOTEPAD You can also specify the direct location of the file by typing the below command. START /MAX C:\Windows\NOTEPAD.EXE *Windows users who have a different directory (e.g. Windows 2000 users) would need to substitute WINNT or the name of their directory in place of Windows in the above example. The /m representing it to start the window Maximized. See our start command page for additional information about this command. Below is an example of how to delay a batch file any where from 5 to 99 seconds. In the below example we illustrate a 5 second delay. TYPE NUL | CHOICE.COM /N /CY /TY,5 >NUL Additionally, you could use the sleep file found on our utility download section. How to make a time log in a batch file The below example demonstrates how to create a time log of when the batch file is loaded, or for example, this could be used in the autoexec.bat when someone logs into a computer that supports this file. ECHO. |TIME > TIME An alternate, slightly more complicated method that, to our knowledge, cannot be used in Windows NT, Windows 2000 or Windows ME would be the following: echo @prompt set
date=$d$_set time=$t$h$h$h > {a}.bat Another alternative is: echo. |time |find "current" >> log For the above batch file to work properly you must create a file called log, by typing edit log and then save and exit the file, creating a 0 bytes file. If this file is not created or not created properly you will receive the error message Content of destination lost before copy.
|
||||||||||||||||||||||||||||||
'IT 세상' 카테고리의 다른 글
windows batch help docs.. (0) | 2009.12.10 |
---|---|
widnows batch pid 체크하기... (0) | 2009.12.09 |
window batch find (0) | 2009.12.09 |
EUC-KR로 표현할 수 없는 한글 처리 (0) | 2009.12.09 |
결함많다던 YF 후배차 시승기 (0) | 2009.12.04 |