5

Is there a way to force-delete a file or a folder even if it is used by another process? I am getting on Windows:

[Error 32] The process cannot access the file because it is being used by another process.

alphanumeric
  • 17,967
  • 64
  • 244
  • 392
  • This looks like it may answer your question: http://stackoverflow.com/questions/13766513/how-to-do-force-remove-in-python-like-rm-rf-on-linux – user2127678 May 11 '16 at 23:05
  • I have tried the solution from the the post to which you specified a link. None of them works for me. – alphanumeric May 11 '16 at 23:12
  • Kill the process using the file. – Natecat May 11 '16 at 23:32
  • The answer to this question may vary depending on the operating system that you are using. Is your goal to delete a single file that is causing you a problem or is it to write code that will delete files that have an open file handle? If you just want to delete the file once then you should grep the process list for processes using the file and then perform a kill -9 (nucelar) on those processes. If you are trying to write code that does this the answer depends on your OS. – aquil.abdullah May 12 '16 at 00:11
  • I presume you are using windows? – Padraic Cunningham May 12 '16 at 01:05
  • It is running on Windows. Need to save the process that uses the file. – alphanumeric May 12 '16 at 01:54
  • @Natecat but what if another machine is using the file? eg. the file is on a network drive. You can't kill a process on another PC. – Theo F Oct 19 '21 at 22:20
  • https://www.technipages.com/windows-how-to-release-file-lock @TheoF – Natecat Oct 23 '21 at 18:03
  • @Natecat I'm afraid I don't have permission to view 'Open Files': Error = 'You do not have permissions to see the list of files opened by Windows clients'. Even though I can manually browse to the file in Windows Explorer.... – Theo F Oct 25 '21 at 17:05

0 Answers0