LPARAMETER cPathToTestLOCAL nFileHandle, cRandomName, cErrorHandler IF TYPE('cPathToTest') # 'C' RETURN .F. ENDIF cRandomName = SUBST(SYS(2015),3,8)+'.WRT' cPathToTest = ALLTRIM(cPathToTest) IF RIGHT(cPathToTest,1) # '\' cPathToTest = cPathToTest + '\' ENDIF * * Certain types of errors such as "Media not present" will present an error back * to VFP rather than simply failing the call and returning a -1. To handle this, * we will disable the current error handler for the duration of the FCREATE() and * set the value of nFileHandle to the error condition if an error occurs, and * we will restore the error handler after the FCREATE() * cErrorHandler = ON('ERROR') ON ERROR nFileHandle = -1 nFileHandle = FCREATE(cPathToTest+cRandomName) ON ERROR &cErrorHandler * * FCREATE() returns a -1 if it failed, telling us we don't have to close * the handle. If it succeeds, we have to close the handle and delete the * 0 byte file created by the low-level I/O calls. * IF nFileHandle # -1 =FCLOSE(nFileHandle) IF FILE(cPathToTest+cRandomName) ERASE (cPathToTest+cRandomName) ENDIF RETURN .T. ELSE RETURN .F. ENDIF