0

1. Summary

I'm couldn't find, how I can unlock or delete locked folder with all subfolders via command-line interface.


2. Argumentation

I'm working on the project. For example, my sources folder — sources, output folder — output. I view files and/or make test changes in output → I add changes to sources → I run build command (build, for example), which should overwrite output. But build doesn't start correctly:

Folder In Use

Folder In Use

The action can't be completed because the folder or a file in it is open in another program

Close the folder or file and try again

Therefore, before each build starting I opened LockHunter → unlocked output → ran build.

It would be nice, if would be possible run command for unlocking or deleting output before build, that I don't need manually run LockHunter every time, spending time on it.


3. MCVE

I created a folder KiraUnlockCLI → opened command prompt → moved to KiraUnlockCLI in it (cd KiraUnlockCLI) → KiraUnlockCLI locked:

Folder locked

I need unlock or delete KiraUnlockCLI programmatically.


4. Requirements

  1. Any type of program can lock output folder and/or files in it, examples:

    1. Windows Explorer
    2. Command prompt
    3. Text editor
    4. Browser
    5. Images viewer
  2. Solution must unlock folders, not files solely. I can open in third-party programs any files in output and its subfolders.

  3. Relative paths must be supported. output is located in different directories for me, another developers and Continuous Integration (Travis CI, AppVeyor).

5. Not helped

5.1. Relative paths

  1. LockHunter doesn't support relative paths.

    At the beginning of September 2019 I wrote an issue → I told about my issue in LockHunter Feedback form → I haven't received any feedback.

5.2. Folders support

These programs can unlock files, not folders.

  1. FileASSASSIN:

    FileASSASSIN /unlock /silent KiraUnlockCLI
    
  2. BusyDelete

5.3. Specific PID

  1. Handle — PIDs required for unlocking. But I need kill processes with any PID; see 4.1 item of my question.

5.4. GUI

I couldn't find any information about command-line interface of these programs:

  1. IObit Unlocker
  2. Unlock IT

5.5. Doesn't work

  1. rm -rf KiraUnlockCLI (rm from GnuWin32):

    /usr/bin/rm: cannot remove 'KiraUnlockCLI`: Device or resource busy
    
  2. OpenedFilesView — no effect after this command:

    openedfilesview /closefolder closeprocess killprocess KiraUnlockCLI
    
  3. WhoLockMe doesn't work in Windows 10.

  4. Unlockerunlocker D:\SashaDebugging\KiraUnlockCLI:

    Unlocker

    No Locking handle found.

    However Unlocker can help you deal with this object.

    Choose the action you want to perform on the object.

  5. DeadLock can't unlock folders via command-line interface. See my issue to DeadLock issue tracker.


6. Don't offer

  1. I'm know side effects; please, don't tell me, that I don't need unlock folder.
  2. I read these SuperUser questions and answers to them before post my question:

    1. Can't delete empty folder because it is used
    2. Is there a way to handle locked file from command line and release it?
    3. How do I delete a folder that's in use?
    4. Delete a directory from the Windows command line even if it's been opened in a program
    5. Delete locked file/folder from command line
  3. I checked programs from this list on the Unlocker site.

1 Answer 1

1

Ever since I've found IOBit Unlocker (~10 years ago) I stopped using all of the ones you supplied and a few others, why? it actually deletes the files/folders no matter what, has clean interface and also you can automate (as you asked). A few years later I've come across an online article stating that it even deletes Avast AV files that are potected and in use.

If you want, you can install and leave it like that or simply get the files and use it standalone (use IObitUnlocker.exe /? to see command line help):

Installed:

IObitUnlocker.exe /Delete /Advanced <folder>

Standalone:

cd <app folder>
sc create IObitUnlocker type= kernel start= demand binPath= "IObitUnlocker.sys"
IObitUnlocker.exe /Delete /Advanced <folder>
sc delete IObitUnlocker
rd /S /Q %AllUsersProfile%\IObit

An automation-wise downside is that displays a message after the action, but you can use timeout /T <time> && taskkill /IM IObitUnlocker.exe. The <time> depends on folder contents/hierarchy, how many files are in use, the speed of your system and the CPU/HDD load). Bear in mind that elevation is needed for unlocking.

If you happen to use AutoHotKey the dialog dismissing (and whatever UI interaction you could think of) is trivially easy to automate.

SetTimer, DismissUnlocker, 1000
DismissUnlocker() {
  If WinExist("IObit Unlocker ahk_class #32770")
    ControlClick, Button1
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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