Hello!
How can I check if a certain file is in use by another process?
I'm trying to delete a file, and sometimes getting an error because it is used by another process.
File.Delete(File.DirApp & "/imp",FileName)
If File.Delete(dir,filename) then...
should return whether file was deleted or not... What
error do you see?
I sometimes run into this issue and just wait for the "next" cleanup cycle to get rid of unwanted files - in case some process has a handle on it (locking it).
This is usually in a temp dir when files are uploaded, download or associated with some DB record and a user deletes it.
At times, I find the OS has not released a handle to it - for whatever reason and it remains kicking around. A server reboot releases the lock - and then it can be removed, however... now we need to code more logic to remove files that couldn't be after restoring the OS.... six of one / half a dozen of the other...
So in the Catch, log to another source table to try again at some other date?
OR - Try 10 times and give up? Not an issue with small files but a 2gig hogs space... and we want it to go - eventually.
I'm using FileWatcher Lib, and now I'm testing if file is readeble or writable before manipulate it.
So, if it is still locked - what do you do?
An issue indeed...