* WaitForFileToWrite.prg - Wait for file to finish getting written to * * This prg was created to address a problem with pdf email attachments. I believe * that the pdfs weren't finished being written to before blat email them out... result was * email with no attachment. This prg will delay the system until a non-zero byte count * is established. * * V1.0 10-Jun-03 EP -Original * */* TO DO: ADD ERROR HANDLING SHOULD THIS PRG FAIL! LPARAMETERS m.lcAttachment LOCAL m.lnAtt LOCAL ARRAY laAtt[1] LOCAL m.ltStart, m.llExit m.ltStart = DATETIME() m.llExit = .f. DO WHILE NOT m.llExit IF FILE(m.lcAttachment) * file exists, loop until file size is not zero or 5 minutes passes m.ltStart = DATETIME() DO WHILE .T. * exit if 2 minutes have passed IF DATETIME() - m.ltStart > 120 m.llExit = .t. EXIT ENDIF * get adir() of the attachment m.lnAtt = ADIR(laAtt, m.lcAttachment) IF m.lnAtt > 0 * array exists IF laAtt[2] > 0 * file size is not zero! OK to leave! m.llExit = .t. EXIT ENDIF ENDIF ENDDO ELSE * loop for 2 minutes if file not found IF DATETIME() - m.ltStart > 120 m.llExit = .t. EXIT ENDIF ENDIF ENDDO RETURN