Prev | Current Page 399 | Next

John Paul Mueller

"Administering Windows Server 2008 Server Core"


Even though the Set command doesn??™t show them, Windows dynamically generates several
environment variables each time you request them, including %DATE% and %TIME%. When working
at DOS, you had to generate these environment variables yourself, which is a time-consuming and
error-prone process (see the examples at http://www.robvanderwoude.com/datetime.html for
details). Unfortunately, these environment variables contain characters that you can use for a filename
including the slash (/) and colon (:). Consequently, you can??™t use the variables directly. The
solution is to extract the numbers you need. For example, to extract the first two numbers of the
time, you use %TIME:~0,2%, where the first number is the starting point in the string and the second
number defines the number of characters to use. Strings in batch file always rely on a 0-based starting
point.
TESTING BATCH FILES 155
TIP When extracting characters from a string, the system assumes that you want to start on the
left side of the string and move to the right. You can reverse this process by using a negative number.
For example, %TIME:~-2% would extract the last two characters in the TIME environmental
variable.


Pages:
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411
Antykoncepcja ATC Athlete sypialnia 2 1