sybex.com/WileyCDA/.
Listing 5.5: Creating a Descriptive Data File Header
@ECHO OFF
REM Add identifying information.
@ECHO Computer: %COMPUTERNAME% > Temps.TXT
@ECHO User: %USERNAME% >> Temps.TXT
REM Add the date and time.
Date /T >> Temps.TXT
Time /T >> Temps.TXT
TESTING BATCH FILES 153
REM Create a header for the data.
@ECHO. >> Temps.TXT
@ECHO Temporary Files: >> Temps.TXT
@ECHO. >> Temps.TXT
REM Locate all of the temporary files on your hard drive.
@ECHO Locating temporary files to delete.
FOR /F %%F IN (DelFiles.TXT) DO Dir %%F /B /S >> Temps.TXT
@ECHO ON
This example uses several techniques to output descriptive data. First, it combines standard text
with environmental variable expansion. Every Windows machine will include the
%COMPUTERNAME% and %USERNAME% environment variables (or you can define them in the unlikely
event that they don??™t exist). Notice the first output contains just a single > redirection symbol, so
this first line always erases any existing file.
Second, the example uses the Date and Time utilities to output the date and the time. Notice the
use of the /T command line switch to prevent these utilities from prompting the user for the date
or time.
Pages:
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408