Wednesday, August 03, 2005

[tech] DOS batch notes

Ask for user input
echo Enter the report date in mm-dd format ...
set /p ReportDate=

Print a blank line
echo.

Verify with Y/N
choice Continue?
IF errorlevel 2 GOTO End

Assign and use of variable
set ReportDate=%1
echo Downloading reports for 2005-%ReportDate%

Call multiple batch jobs from one batch file
call [batchfile1]
call [batchfile2]

Check for null
IF "%1" == "" GOTO :Ask-for-date

Dedupe lines in a sorted file
FOR /F %%i in (requestlog.all) DO (
FOR /F %%j in (requestlog.tmp) DO (
IF not %%i equ %%j echo %%i >> ToDo.%TargetDate%.txt
IF not %%i equ %%j echo %%i > requestlog.tmp
)
)

Delete files only if they exists (so you don't end up with the error msg)
FOR %%F in (requestlog.*) DO DEL %%F

Great reference site
http://www.computerhope.com/batch.htm