File Lock Discovery

  • Thread starter Thread starter Justin
  • Start date Start date
J

Justin

Hi all,

Does anybody know a way, in VB.Net, I can discover the file locks on a file
on the local machine. I have an application which needs to delete specific
files, but I would like to verify in advance whether or not a particular
deletion will succeed. Due to other pre-deletion actions, I cannot attempt
the deletion and catch the exception if it fails.

Thanks in advance

Justin
 
Hi, Justin

As locks are dynamic in such cases your best bet would be to use try/catch
around the code. I am not sure I can see why pre-delete actions are not
allowing you to use this simple and efficient approach. Would you care to
explain?

HTH
Alex
 
Hi Alex,

Thanks for your reply.

The reason I wanted to 'pre-validate' the deletion is because I need to unregister the file for COM, prior to deletion. If I do not do this and the deletion succeeds I have missed my opportunity to do the unregistration. So I unregister and try to delete, if the deletion fails I have an 'undo' process that re-registers the file.

This solution does work. I had just wondered if there was a straight forward way of checking, prior to deletion. If, as it appears, there is not then so be it, I will stick to the solution I have.

Thanks

Justin
 
Back
Top