Salvatore,
As Carlos wrote, you should use FExists() rather than Directory() to check
for the existence of the file, and use Sleep() to not use 100% of the CPU
cycles. In addition, I would suggest that you add some sort of event check
after the Sleep(), so that the application doesn't become unresponsive:
Function Wait_For_File(cPathName, cFileName)
LOCAL nEvent := xbeP_None, mp1, mp2, oXbp
LOCAL nWait := 0
for nWait := 1 to 600 Wait 5 Minutes at most
if FExists(cPathName + cFileName)
return (.t.)
else
Sleep(50) Wait 1/2 a Second
if NextAppEvent() # xbe_None
while (nEvent := AppEvent(@mp1, @mp2, @oXbp, 0)) # xbe_None
if ValType(oXbp) == 'O' .and. oXbp:Status() == XBP_STAT_CREATE
oXbp:HandleEvent(nEvent, mp1, mp2)
endif
enddo
endif
endif
next nWait
return (.f.)
That way, you could also allow the user to cancel the wait, for example.
Hope that helps,
Andreas

Hi,
just add one next test after test of existence target file:
it will test/wait if file is not only created(exists), but if it is already
accesible for other procceses than pdfcreator at the test' time.
I use it in this way in one my app, because without this while bigger/big
report/file is created/generated, pdf file is although created, but still
not yet ready for use/read/show - pdfcreator blocks it.
Trick is trying rename file to any temp-file and if it is
successful(pdfcreator finished work yet), just rename it back.
cTempFile := (cPathName + 'temp.pdf')
...
if FExists(cPathName + cFileName)
* return (.t.)
if ( FRename( (cPathName + cFileName), cTempFile ) == 0 )
FRename( cTempFile, (cPathName + cFileName) )
return (.t.)
endif
else
...
Regards,
Zdeno