How to know whether the file is not trying to open it?
- Eugene Lutsenko
- Posts: 1649
- Joined: Sat Feb 04, 2012 2:23 am
- Location: Russia, Southern federal district, city of Krasnodar
- Contact:
How to know whether the file is not trying to open it?
Whether the file you need to know before removing or replacing, to issue an appropriate message to the user before execution error occurred.
Re: How to know whether the file is not trying to open it?
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.
greetings by OHR
Jimmy
Jimmy
Re: How to know whether the file is not trying to open it?
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
The eXpress train is coming - and it has more cars.
- Eugene Lutsenko
- Posts: 1649
- Joined: Sat Feb 04, 2012 2:23 am
- Location: Russia, Southern federal district, city of Krasnodar
- Contact:
Re: How to know whether the file is not trying to open it?
Thank you!
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.
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.
Re: How to know whether the file is not trying to open it?
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. 

Best regards,
Tom
"Did I offend you?"
"No."
"Okay, give me a second chance."
Tom
"Did I offend you?"
"No."
"Okay, give me a second chance."
Re: How to know whether the file is not trying to open it?
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
The eXpress train is coming - and it has more cars.
- Eugene Lutsenko
- Posts: 1649
- Joined: Sat Feb 04, 2012 2:23 am
- Location: Russia, Southern federal district, city of Krasnodar
- Contact:
Re: How to know whether the file is not trying to open it?
Thank you so much! Try as would be the time. I think everything will turn out. How to tell if a file in the folder, or it is not of course I know. Simply because of the lack of English and the use of an automated translator can not articulate the question. Once again, I apologize and thank you so much.
- Eugene Lutsenko
- Posts: 1649
- Joined: Sat Feb 04, 2012 2:23 am
- Location: Russia, Southern federal district, city of Krasnodar
- Contact:
Re: How to know whether the file is not trying to open it?
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.
- Eugene Lutsenko
- Posts: 1649
- Joined: Sat Feb 04, 2012 2:23 am
- Location: Russia, Southern federal district, city of Krasnodar
- Contact:
Re: How to know whether the file is not trying to open it?
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