My Web Sites

Recent site activity

Software Tools‎ > ‎

DOS Batch Programming

General Rules

Named parameters are enclosed in percentage signs, as in %name% while input parameters are numeric and use only one percentage sign, as in %1.

WAIT

In command prompt there is no direct support for timed wait command. However, there is Choice command that has a time parameter that indicates how long it should wait for selection. This can be used for timing.
In Windows 7 this can be done in the following way (in this example we wait for 5 seconds):

CHOICE /N /C Y /T 5 /D Y >NUL

Directories

Current Directory

%CD%

Changing Directories

Use PUSHD/POPD to switch directories.

IF Command

Example of conditional branching:

@ECHO OFF
:TOP
   IF (%1)==() GOTO END
   ECHO Value is "%1" and still running...
   SHIFT
GOTO TOP
:END

See attached if.cmd.txt file for example.

Date and Time

See attached script.

Links

  • Windows XP Command Syntax (link).
  • Top 10 DOS Batch Tips (link)
Č
ċ
ď
datetime.cmd.txt
(0k)
Alen Šiljak,
Jul 12, 2010 6:46 PM
ċ
ď
ifelse.cmd.txt
(0k)
Alen Šiljak,
Oct 4, 2010 6:36 PM