1

如果目录已经存在,我正在制作一个删除目录的函数,那么无论目录是否已经存在,它都会在之后创建它。

我第一次运行代码时,它运行良好,但是如果我再次尝试运行它,则会弹出以下错误:[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)       
4

1 回答 1

0

您可以尝试使用该文件夹查找进程,然后将其终止。找出哪个进程正在锁定 Windows 中的文件或文件夹

于 2021-02-14T04:25:16.460 回答