How to know whether the file is not trying to open it?
Posted: Mon Oct 27, 2014 3:43 am
Whether the file you need to know before removing or replacing, to issue an appropriate message to the user before execution error occurred.
Donnay Software Web Forums
http://bb.mobile.donnay-software.com/Donnay/
http://bb.mobile.donnay-software.com/Donnay/viewtopic.php?f=2&t=1330
using "SHFileOperationA" API with "Copy" / "Rename" you can get a Warning like in Explorer.Eugene Lutsenko wrote:Whether the file you need to know before removing or replacing, to issue an appropriate message to the user before execution error occurred.
Code: Select all
IF !FExists('C:\test\junk.dbf')
DCMSGBOX 'File does not Exist!'
RETURN .f.
ENDIF
IF FExists('C:\test\junk.dbf')
DCMSGBOX 'File Exists!. Overwrite?' YESNO TO lStatus
IF lStatus
// Overwrite file
ENDIF
ENDIF
RETURN lStatus
Give this a try:And how to determine the file is opened or closed, that is, whether it is used? My question is not about DBF file, and about XLS.
Code: Select all
FUNCTION IsFileOpened( cFileName )
#include "fileio.ch"
LOCAL lStatus := .t.
LOCAL nHandle := FOpen( cFileName, FO_READWRITE+FO_DENYWRITE) )
IF nHandle <= 0
DCMSGBOX 'File is in use. Try again later!'
lStatus := .f.
ELSE
FClose(nHandle)
ENDIF
RETURN lStatus
Simple and original thought. Strange that she did not come to my head ...Tom wrote:MS Office creates a hidden file with a prefix "~$" when a file (xls, doc) is opened. So, you can check if "~$myfile.xlsx" exists if you're trying to delete "myfile.xlsx". This indicates that the file may be in use. Sometimes, those temporary files are not deleted properly, so the temporary file (containing the windows-username of the person who opened it) is still there. The best indicator that a file is in use is: Try to delete it. If this fails, it is in use.
Roger! Thank you so much! Everything turned out great! I know the file is open or not without trying to open it (and other operations without check temporary files) and it is obtained for all types of files and programs using them. This is exactly what I needed.rdonnay wrote:Give this a try:And how to determine the file is opened or closed, that is, whether it is used? My question is not about DBF file, and about XLS.
Code: Select all
FUNCTION IsFileOpened( cFileName ) #include "fileio.ch" LOCAL lStatus := .t. LOCAL nHandle := FOpen( cFileName, FO_READWRITE+FO_DENYWRITE) ) IF nHandle <= 0 DCMSGBOX 'File is in use. Try again later!' lStatus := .f. ELSE FClose(nHandle) ENDIF RETURN lStatus