Windows Environment Variables


quasi-undocumented, tested under W2000 and WinXP, see SET /?

If Command Extensions are enabled, then there are several dynamic environment variables that can be expanded but which don't show up in the list of variables displayed by SET. These variable values are computed dynamically each time the value of the variable is expanded. If the user explicitly defines a variable with one of these names, then that definition will override the dynamic one described below:

%CD% - expands to the current directory string.

%DATE% - expands to current date using same format as DATE command.

%TIME% - expands to current time using same format as TIME command.

%RANDOM% - expands to a random decimal number between 0 and 32767.

%ERRORLEVEL% - expands to the current ERRORLEVEL value

%CMDEXTVERSION% - expands to the current Command Processor Extensions version number.

%CMDCMDLINE% - expands to the original command line that invoked the Command Processor.

To use today's date in a filename... You need to know what format it is on on your server, determined by control panel/regional settings, on my workstation that is:

    C:\> echo %DATE%
    10/07/2011

You can extract from an variable by: %var:~skip,count%, where "skip" is the # of characters to skip and "count" is the number of characters to grab. So for example:

  C:\> echo %DATE:~6,4%%DATE:~0,2%%DATE:~3,2%
     20111007

You can also play the same game with the %TIME% environment variable.


keywords: xp,2000,2k,win2k,w2k
date: 05/04/2005