I'm making a function that deleats a directory if it already existed, then no matter if the dierctory already existed or not, it creates it afterwards.
The fist time I run the code, it works well, but if I try running it again, the following error pops: [WinError 32] The process does not have access to the file because it is being used by another process. I do not have anything else open so I don´t know where the error might be coming from
I´m using Windows 10 and Python 3.8.5
import os
import shutil
Path_1 = "D:/felip/Redes_Neuronales_Team/Redes_Neuronales_Pruebas/Prueba_del_programa/DirA"
Path_2 = "D:/felip/Redes_Neuronales_Team/Redes_Neuronales_Pruebas/Prueba_del_programa/DirB"
#For the 1st Directory
if os.path.exists(DirA):
shutil.rmtree(DirA)
#For the 2nd Directory
if os.path.exists(DirB):
shutil.rmtree(DirB)
os.mkdir(DirA)
os.mkdir(DirB)