我正在创建一个函数,如果目录已经存在,则删除该目录,然后无论该目录是否已经存在,它都会在之后创建它。
我第一次运行代码,它工作得很好,但如果我再次尝试运行它,下面的错误弹出:[WinError 32]进程不能访问文件,因为它正在被另一个进程使用。我没有打开任何其他东西,所以我不知道错误可能来自
我正在使用Windows 10和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)
您可以尝试使用该文件夹找到该进程,然后杀死它。查找哪个进程正在锁定Windows中的文件或文件夹