Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I was wondering if there is a command-line tool that allows me to close all file handles that are open under a specific folder.

I have tried ProcessExplorer, Unlocker and similar tools, but they offer a GUI interface, and are not useful in a programming environment

A solution on Python, cmd or PowerShell would be ideal.

share|improve this question
    
Remember that forcibly closing a file handle might cause the program using that handle to crash. –  Harry Johnston Sep 15 '11 at 3:02
add comment

3 Answers

up vote 2 down vote accepted

Unlocker does claim it gives you this ability:

  1. Simply right click the folder or file and select Unlocker

    Step1

  2. If the folder or file is locked, a window listing of lockers will appear

    Step2

  3. Simply click Unlock All and you are done!

I'm not sure if it supports command-line usage.

MalwareByte's FileAssassin performs similar actions, and does support command-line usage, so you should be able to script it pretty easily.

FileAssassin's Switches

share|improve this answer
    
Thanks techie007, I guess I missed that. I noticed that Unlocker sometimes misses my files (ProcessExplorer doesn't).. A second issue is if I want unlock or release files programatically (e.g. a command line tool would help along this direction). –  user815423426 Sep 13 '11 at 19:27
    
@intrpc There ya go, I added another (command-line-friendly) suggestion. :) –  techie007 Sep 13 '11 at 19:49
    
This looks great! Thanks! –  user815423426 Sep 13 '11 at 20:32
add comment

We use the following snippet to close file handle from users to our server. You may be able to modify it for your use.

rem close all network files that are locked
for /f "skip=4 tokens=1" %%a in ('net files') do net files %%a /close
share|improve this answer
    
Thanks @Brendan. I think your code was not formatted properly. Your answer looks interesting, so if you don't mind editing it, I would suggest that you select your lines of code, and then click the button with the two curly bracelets. That will turn your snippet into readable code. –  user815423426 Sep 13 '11 at 21:22
add comment

I prefer http://lockhunter.com because it supports both GUI and command line interface, and in many cases was able to delete files that could not be deleted by Unlocker.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.