Procedure CanOpenFileExcl * procedure to see if a file can be opened exclusively by opening the file with FOPEN(); can be used * with any file; note that file is closed after opening so it is an "instantaneous" check i.e. the * file could still be locked after this function returns; note also that if the file does not exist, it also * returns .F. as this is a test if it can be opened: so should test for file existence before calling * Big Note: you are going to have to check to see if the function really does detect if the file is open * or not; the code below opens in read/write unbuffered mode so that it fails to open a file that cannot * be shared in this way; but some files can [could?] be opened shared like this even if they are opened by * another application: do your own testing...I have found the following so far: * 1) a .dbf file that is not open already: returns .T. * 2) a .dbf file that is open already in shared mode or exclusive mode: returns .F. * 3) a .pdf file that is open in the Acrobat viewer: returns .F. * 4) a .xls file that is open in Excel opens .F. * Written by: Albert Gostick * Last Updated: Aug 18, 2006 * Parameters: * tcFileName: full file name and path i.e. path is required * Returns: .T. if file can be opened exclusively, .F. otherwise Lparameters tcFileName Local lnHandle, llReturn * default return value Store .F. To m.llReturn * check that file exists; if it does not exist, then we should return .F. If Not File(m.tcFileName) Return m.llReturn Endif * try to open the file in read/write unbuffered mode as this fails if file is open by another application * (even within FoxPro) if it cannot be shared Store Fopen(m.tcFileName,12) To m.lnHandle * if lnHandle is -1, it could not be opened; if it was opened, file handle will be a positive value If m.lnHandle > 0 * file was opened; close it and set return value Fclose(m.lnHandle) Store .T. To m.llReturn Else Messagebox( "Tabel kan niet gesloten worden", 0+16+0, "Tabel is door iemand geopend", 0 ) && OK = 1 Endif Return m.llReturn Endproc <@Sergey