I want to delete a directory with files owned by other processes in Windows 7. Other answers say to find the process that is accessing it which I do not want to do.

I tried using PowerShell and couldn't even get past deleting non-empty directories without having to resort to writing a script which I will never ever do.

I tried using the Bash command rm -rf ./directory and I got the error The process cannot access the file because it is being used by another process

I tried import shutil \ shutil.rmtree('./directory') in Python and got the same error.

The other process can die, I don't care. It's my file and I'm an administrator. How do I say "I really mean it, I don't care about the consequences, just do what I ask, computer, for the love of all that is good."

Clarification: I do not care and do not want to care which other process is accessing the files. I also would like to use the command line if possible.

  • 3
    Possible duplicate of Can't delete empty folder because it is used
    – Sandeep
    Jul 18, 2018 at 14:20
  • 1
    NO!!! That is not a duplicate. The accepted answer to that question is to find the process that is accessing the file. That is exactly what I don't want to do, that's stupid, I want to delete the file, not pick up a second job every time I want to delete my temp dir.
    – Max Heiber
    Jul 18, 2018 at 14:23
  • 4
    A locked file in windows cannot be deleted without killing process which has locked the file. However, this process (killing the process and deleting the file) can be automated using batch or power shell script. It that what you need?
    – Sandeep
    Jul 18, 2018 at 14:26
  • 1
    File locking, opening and whatnot is different on Windows and Linux. Read this.
    – Daniel B
    Jul 18, 2018 at 14:34
  • 3
    Close Voters: While the proposed dup's answers are the only way to delete locked files, this question is expressly distinct from the proposed dup. As far as I can tell we mark questions dup based on the content of the question, not on whether the answers may be the same. Aug 2, 2018 at 23:12


You must log in to answer this question.

Browse other questions tagged .