Batch commands are a holdover from the MS-DOS time, but they are far from obsolete. We tell you the most interesting batch commands that can solve their tasks that Windows can not do so quickly alone.
Batch commands writes to her in a batch file. Elsewhere we have explained in detail how to create a batch file. Such a batch file is basically a text file that contains one or more commands. This may be commands that are built into the operating system, but also normal subroutine calls. Your even can call with batch commands other batch files. Much of what do these batch commands also can finish your mouse in Windows. But just only one at a time. Send batch commands a stack of commands with a command from what goes much faster.The output of the batch commands in the command window
Basically, you get all the available command line commands of Windows appears when you open under under the Run dialog prompted with CMD and then eingebt the HELP command. For each area of command gets your application and the individual parameters called if its a /? Appends. So about COPY /?Start Photogallery(17 images)make Windows faster: The best tools
Standard batch commands - examples
|@ECHO OFF||Ensures that the output window, the commands are not displayed.|
|ECHO||Shows what is in the batch file behind it. ECHO Hello Erwin outputs Hi Erwin.|
|PAUSE||Stops the execution of the batch commands, until a button is pressed. May, for example at the end of a batch file, so you can check for error messages the output window again.|
|REM||REM stands in front of a line of the batch file, the line is considered a comment and not executed as a command. So you can comment out about commands that are not run at this.|
|DEL or ERASE||Deletes one or more files. May individually or simultaneously with the following appended parameters are called: / P - asks before each deletion to confirm.|
/ F - will also delete read-only files
/ S - also deletes all files in all subdirectories
/ Q - No further inquiries with wildcards such as * *.
/ A - Erases files by their file attributes. So clears about / A: H only hidden files.
|TO YOU||Lists all files and directories in the current directory auf.DIR * .JPG lists only files with the extension JPG, usw.DIR / P is useful for folders with many files as / P turns on a break after each output window. DIR / S lists subdirectories.|
|COPY COPY (source) (destination)||COPY * .doc D: \ DOCS - copies all files with the extension DOC NAMES.TXT voramen.txt the specified Verzeichnis.COPY - Creates a copy of the file NAMES.TXT and calls them vornamen.txt.|
|EXIT||Closes the output window after all the batch commands have been processed.|
|RD (Remove Directory)||Deletes Verzeichnisse.RD / S / Q path &# 8211; deletes all files, directories and subdirectories in the specified path (/ S) without asking (/ Q).|
Unusual batch commands
Anyone can use batch commands such as DEL or XCOPY and add a few more fixed parameters and paths. But there are also some rather special batch commands, but which can greatly help you.
|Batch command||example call||usage example|
|%CD%||MOVE * .docx &# 8220;%CD%/ DOCS /||The% CD% of the entire current path is replaced. In the left-standing call so all files will be moved with the extension .docx to a subdirectory of the current path. Commands such as MOVE need to perform the complete path that you do not have to enter in this way. So with such a command you can clean up directories and move data effectively.|
|% 1,% 2,% 3 ...||Batch line:|
echo So you say %1
|Batch commands can process multiple variables. You call the batch file and inserts manually the contents of the variable back to the command an.Die command line batch.bat Huhu Hello Tach So passes the three variables Huhu, Hello and tach to the batch commands in the batch file. Your order specifies the same also determine the number of the variable. Since Hi is in second place, it would used where is filed in batch file% 2. Huhu is therefore% 1 and Tach% 3. If in the batch file only one variable is used, in addition passed variables are ignored.|
|> (Greater than sign)||TO YOU *.* > liste.txtDIR *. * > NUL|
(NUL output suppressed in this case completely)
|The greater than sign > is a redirector for batch commands. Instead ie at about DIR *. * To list all files in Windows, this character ensures that the output of the command is redirected to a file. Which then provides a list of all files and their attributes.|
|CHOICE||choice / M &# 8220; Do you want a listing, Yes or No&# 8221;|
IF ERRORLEVEL 2 GOTO Make2
IF ERRORLEVEL 1 GOTO label1: Make2
to you *.*
|CHOICE prompts the user for a decision. This can be preset and contain letters or numbers bestehen.Die ERRORLEVEL are processed from back to front. The first answer (as Yes) returns 1 ERRORLEVEL, the second selection yields ERRORLEVEL 2 usw.Ihr then can jump to jump labels, behind which follow commands.|
CHOICE /? Explains the batch command.
Characteristics of the batch commands
Batch commands are executed one after another. This not only means that they are executed in a predetermined order. This means in particular that the subsequent instruction waits until the previous is finished! So you will not start as with a batch command five applications at once, but five programs consecutively.
Batch commands can be called with parameters in turn. So if you are not just clicking a batch file, but manually calling on the command line, then you can still attach behind a few other parameters. A small example:
If a program creates its own temporary folder on any media, and it does not clean, then you could write to correct a batch file. The file weg.bat then contains, for example, the line
del C: \ TEMPSCHROTT
But if it is always such a folder on D: and E are, then would have to be specially considered. So you wear either for each of these drives another line, or you use a variable as a placeholder. These variables can enumerate her and the first is, therefore,% 1. Puts them where something changes. So in my example the drive letter. The line is then
del %1: \ TEMPSCHROTT
And is called the weg.bat with the attached variable. The call weg.bat C deletes the folder on drive C :. And starts her weg.bat e, then the folder is on E: deleted.
Important: It is just that taken in the variable, which is afterwards added manually. Without this input variable batch commands do not work. And you had as a batch command equal del% 1 taken, so you would have the whole path manually attached to the batch file.
always reach batch commands
Usually your batch files are not necessarily where they are needed. So you need to either get copied, where they are needed, or specify as variables endless paths. But finally there is the system environment variables on Windows.customize system environment variables to achieve batch commands always
You have only the global path in the system environment variables check and correct so that you can use from your batch commands from anywhere.
- Gets the key combination Windows key + X the menu and selects there system. In Windows 7, you can in the Control Panel in the search box the word &Environment variables; # 8220&# 8221; enter and also got there.
- Left goes to Advanced system settings.
- in the Advanced tab goes to the lower Environment Variables button.
- Power below for system variables one Double-click on Path.
- There, either add the path to your batch file, or movies, where you may be able place to achieve them forever. (For example, in the folder C: \ Windows).
- Save and batch commands are system-wide on all drives.
more on the subject
- The main CMD commands
- grab WinRAR files with batch commands
- shutdown Windows using a batch file
Posted In: software