13

Is there a way to detect locked files in specify folder and release them by command line?

Something like this in pseudo-code:

for file in folder do
unlock file
Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
David Michaeli
  • 777
  • 4
  • 11
  • 22
  • What's the real problem? – web_bod May 20 '12 at 09:15
  • -1! Bad question for http://stackoverflow.com .. must be asked on http://superuser.com – Asif May 20 '12 at 09:16
  • @Asif Did you know that you can use the "flag" link underneath the question's tags to suggest that it be migrated to another, more appropriate site? – Cody Gray - on strike May 20 '12 at 10:05
  • 8
    A guy asks if a specific feature in the Windows API exists so he can write a utility program, and that's not a programming question and belongs on superuser? I don't get it. – skiphoppy Jun 19 '12 at 19:11
  • The question doesn't ask if the feature exists in the Windows API, he asks for a way to do it by the command line. The command line is not a programming language, or a programmatic interface. It's a user interface, just like Windows Explorer. – Cody Gray - on strike Jan 21 '16 at 04:19
  • 1
    This is a task that a programmer is likely to have to do. If you must move the question, go ahead and move it. But for a programmer who just wants to get something done, closing a question like this just gets in the way. It is frankly by far the most annoying thing that regularly happens on SO. – William Jockusch Mar 19 '18 at 20:22
  • @CodyGray - There are probably several people who hang in the [cmd] tag that might disagree with you. – lit Mar 19 '18 at 21:32

2 Answers2

23

Yes, this is possible using a free utility called Handle, by Mark Russinovich.

It can be download here from Microsoft.

This runs from the command line, and will tell you which program has a particular file or directory open, based on whether it has an open handle to that resource.

By running handle.exe with the -c flag, you can also force the specified handle closed, which will unlock the resource. But fair warning: this will likely cause the application using the resource to crash, perhaps even the entire system to become unstable. So I wouldn't make a habit of doing this; only use it for special cases like debugging where you expect some instability.

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
  • 2
    Thanks, but it seems that it harder to work with handle.exe, because it should to get the pid, i want to create a batch file that know to search foreach a file is in the specific folder and unlock it.. – David Michaeli May 20 '12 at 10:23
  • @David Harder than what? That seems like a really strange plan. If applications are *using* those files and you close all the handles, you've got a serious problem on your hands. – Cody Gray - on strike May 20 '12 at 10:28
-4

No, you can't you have to close the application holding the lock first. Unlocker may help you locate the source of the lock - if it's a crashed application then you'll be able to terminate it's process.

web_bod
  • 5,728
  • 1
  • 17
  • 25