Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Deleting Locked File
#1
Hi Gintaras,
When trying to read, write to or delete a certain file, I keep on getting a dialog called "Error Deleting File or Folder"
Cannot delete XXXXXXXX. It is being used by another person or program. Close any programs that might be suing the file and try again.


I think this is due to a glitch in another software that writes this file out from a Tcl script. If the script fails without closing the file properly, it remains locked in this way. I don't know why it intermittently fails but the problem could be solved if I simply deleted the pre-exisiting locked file.

I see some software online that does this:
see http://www.thefreecountry.com/utilities/...iles.shtml

but I was wondering if this is something that could be handled by QM?

Thanks, Stuart
#2
No, qm cannot delete or unlock locked files.
I use Unlocker.
#3
Thanks Gintaras,
Unlocker worked to delete the file but I thought you had to go through it's dialogs so therefore I couldn't script it (elegantly ;-) I can do ANYthing with QM of course!!!) but I just saw that you can run it from the command line:

run Unlocker.exe Object [option]

object: complete filepath

Option:
/S unlock file
/D delete file


now I can run this in my QM function as an err statement

I am back in action!!!!
Thanks!!!,
Stuart
#4
Is it possible to checked if folder or file is locked?
(Not unlock it, but just check if it is locked?)

There was a thread about "Wait for a file in directory":
Wait for a file in directory

But I was wondering if there was a way to just check if a file/folder is locked.
#5
Try to open the file with CreateFile, without sharing flags. If returns -1, call GetLastError. If it returns ERROR_SHARING_VIOLATION or ERROR_USER_MAPPED_FILE, the file is locked. If CreateFile returns not -1, call CloseHandle. All these are Windows API functions, look in MSDN library.

Note that some process may open (lock) the file immediately after your "is file locked" code says that the file is not locked.

Another way - Restart Manager API. But I did not try it. It seems it knows what processes use the file and can restart them. Vista+.
#6
Ok thank you!


Forum Jump:


Users browsing this thread: 1 Guest(s)