Verifying whether the file is opened before deleting

I have a situation in which I am deleting a file using Kill(Path), but before deleting the file I need to check whether the file is opened by user through another application so that I can prompt the user that the file is in use before deleting. How can I achieve it.

Briefly how can I check whether the file is opened by some other application. File may be of any extension like .xls, .doc, .txt.
lesaAsked:
Who is Participating?
 
watyConnect With a Mentor Commented:
You can open the file as lock before killing it :
Open "TESTFILE" For Binary Access Read Lock Read Write As #1
0
 
lesaAuthor Commented:
Sorry for the delayed response. I don't want to open the file, I just want to delete the file and before that I need to verify if the file is being used by some other application so that I an propmt the user to close the file before deleting.
0
 
watyCommented:
This is the only solution. To know if the file is open, you need to access it. There is nowhere a property set telling that the file is currently openend.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.