0

when the remove part is getting executed, i got a "file already in use error". is there any way i can add some sort of check that the file is fully closed or forcefully delete it? I also tried it with pathlib.unlink and with subprocess but not work either!

if os.path.exists(os.path.join(path_files_folder, file)):
    os.remove(os.path.join(path_files_folder, file))
AcK
  • 2,063
  • 2
  • 20
  • 27
shailu
  • 190
  • 1
  • 10
  • 4
    I don't think you can forcefully delete it because IT IS BEING used. You need to kill the process that is accessing it. And if its okay to not delete such files, you can follow the Python Zen and catch the exception and move on. – gsb22 Jul 26 '21 at 05:29
  • You should read this: https://stackoverflow.com/questions/11114492/check-if-a-file-is-not-open-nor-being-used-by-another-process – Jesper Jul 26 '21 at 05:32
  • related: https://stackoverflow.com/questions/10504647/deleting-files-in-use – Jan Wilamowski Jul 26 '21 at 05:32
  • Which operating system are you on? Please edit your question and add the relevant tag. – AcK Jul 26 '21 at 05:41

0 Answers0