                                FYI

(Note: The origin of this information may be internal or external
to Novell.  Novell makes every effort within its means to verify
this information.  However, the information provided in this
document is FOR YOUR INFORMATION only.  Novell makes no explicit or
implied claims to the validity of this information.) 

          TITLE: Batch Programming and Zero Byte Files
   DOCUMENT ID#: FYI-M-1118
           DATE: 13OCT92
        PRODUCT: DR DOS
PRODUCT VERSION: 6.0
     SUPERSEDES: N/A

        SYMPTOM: Unable to copy zero byte files.

ISSUE/PROBLEM
Since the release of DR DOS it has always had the ability to copy
zero byte files. Recently we have found, however, that by limiting
the ability of DR DOS to copy such files, we can increase the
abilities of batch programs.  This change has been made in the 7-92
and 11-92 COMMAND.COM. This latest COMMAND.COM is available on
CompuServe or the Novell DSG Host BBS (408-649-3443). 

One example of this is the ability to create a batch program that
will only execute a certain command or group of commands once a
day.

The following is a set of instructions that will generate an
example of a batch file and it's necessary text files that can be
executed multiple times daily (say from the AUTOEXEC.BAT file), but
will only perform the defined task once a day:

1.   Create a file called DTFRCMP.TXT that contains the current
     date information by typing the following from the command
     line:

     C:\>DATE >DTFRCMP.TXT
     Press the Enter key twice and you will be returned to a
     prompt.

2.   Create a file called CR using the editor (EDITOR.EXE). All
     that this file will contain will be a carriage return. To
     create it do the following:

     a.   From the command line (C:\>) type: EDITOR CR
     b.   You will then be asked if you wish to create a new file.
          Type Y.
     c.   You will then be in the editor.  Enter a carriage return
          by pressing the ENTER key once.
     d.   You will then need to save the file.  Do this by holding
          the Ctrl key down and then typing K and then X.

3.   Now you will need to create the main batch file that performs
     the daily routine.

     a.   From the command line (C:\>) type: EDITOR TEST.BAT
     b.   You will then be asked if you wish to create a new file. 
          Type Y.
     c.   Then proceed to type in the following lines (thus
          creating the file):

@ECHO OFF
REM This logs the date information into a file.
DATE <CR >INF.TXT
REM This compares the preexisting date information
REM with the date information that was just created.
REM It creates a file with this information.
COMP INF.TXT DTFRCMP.TXT >CMP.RZT

REM This looks for the word "failure" in the created
REM text file. (This would be an indication that the
REM files are the same if "failure" was not found)...
REM Thus telling us that this batch file has already
REM been run today.
REM It pipes the results into a file.
FIND "FAILURE" CMP.RZT >DECIDER.TXT

REM If "failure" was found, then the file that was 
REM created will have a file size.  If it was not
REM found then it will have a zero byte file size.
REM This will try to copy the file to another file.
REM If the original file is a zero byte file then
REM this procedure will fail because the COPY 
REM command cannot copy a zero byte file.
COPY DECIDER.TXT FINAL.TXT >NUL

REM This checks to see if the final file was created.
REM If it was not, then the daily routine will be
REM bypassed...this batch file has already been run today.
IF NOT EXIST FINAL.TXT GOTO FINAL

REM If this section has been reached, then the batch
REM file has not been run today and it is going to 
REM execute the once-a-day command that it is intended
REM to execute. This can be any command of your choosing
REM as long as it works from the DOS prompt.  The one that
REM has been chosen here is a command that copies the
REM config.sys file to a filename called ITWORKED.SYS.
:COPY
COPY C:\CONFIG.SYS C:\ITWORKED.SYS >NUL
ECHO Executing once-a-day routine...
REM This creates a new date-comparison file so that the
REM next time that this batch file is run it will see 
REM that it has already been run today.

COPY INF.TXT DTFRCMP.TXT >NUL

REM This deletes the final comparison file that was created
REM today.
DEL FINAL.TXT

REM This cleans up all of the extra files and exits.
:END
DEL INF.TXT
DEL CMP.RZT
DEL DECIDER.TXT
EXIT

REM This tells you that it has already been run today.
:FINAL
echo Daily routine has already been run today.
GOTO END


Now, if TEST.BAT is executed many times daily, it will only create
the file ITWORKED.SYS once a day.

Please note: If you attempt to run this batch file on the same day
that you created it, it will respond that the routine has already
been run today.  This is because the information in the DTFRCMP.TXT
file is the same as the current day's date.  If you wish to test
it, you will have to change the date.

This file can be incorporated in the AUTOEXEC.BAT file to execute
every time the computer is turned on.  To do this, use the editor
and add the following line just before the line :DRDOSEND:

CALL TEST.BAT

Some possible uses of such a batch file would be running a daily
virus scan, running system diagnostics or running the disk
optimizer.