3

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.

Max Heiber
  • 148
  • 1
  • 7
  • 3
    Possible duplicate of [Can't delete empty folder because it is used](https://superuser.com/questions/1333118/cant-delete-empty-folder-because-it-is-used) – Sandeep Jul 18 '18 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 '18 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 '18 at 14:26
  • 1
    File locking, opening and whatnot is different on Windows and Linux. Read [this](https://superuser.com/q/388861/219095). – Daniel B Jul 18 '18 at 14:34
  • 1
    @Sandeep, sure that would work. It's dumb, but better than nothing. Linux and OS X seem to handle this sanely, but I'll take what I can get. – Max Heiber Jul 18 '18 at 14:40
  • 1
    @DanielB, thanks I understand that Windows is broken in this regard, I'm looking for a workaround that doesn't involve clicking around in a GUI like some kind of cave person. – Max Heiber Jul 18 '18 at 14:42
  • @MaxHeiber Believe [This](https://superuser.com/q/1002737/899278) is what you need. Look at accepted answer for command line to find and terminate process which is locking the file. – Sandeep Jul 18 '18 at 14:46
  • 1
    It does depend on the kind of lock though. I have had luck using `rd FolderName /s` to delete a folder and its content regardless of a lock. But if a file is actually being written to, then it will still fail. – LPChip Jul 18 '18 at 14:47
  • 1
    Windows is not "broken" in this regard. It just handles these things differently. OSx and Linux do things differently because they are different from Windows. They do things the same as each other because they are both derived from Unix. If you have to work on Windows, you must accept the differences and not resort to saying it's broken just because it doesn't behave how you personally want it to. – music2myear Jul 26 '18 at 17:46
  • 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](https://stackoverflow.blog/2009/04/29/handling-duplicate-questions/), not on whether the answers may be the same. – I say Reinstate Monica Aug 02 '18 at 23:12

0 Answers0