Command Line – How to Delete Locked Files or Folders in Windows?

command linefile managementwindows

It is easy to delete a file or folder from a command line or a locked file or folder from a nice GUI tool like Unlocker.

However is there a way to delete locked file/folder from a command line?

Best Answer

Sysinternals Handle can list all open handles (to files and other objects), as well as close them. Run handle filename to list all matching handles, then handle -c id -p pid to close it. This is basically the same as what Unlocker does.

(Edit: Added forgotten -p option.)