话不多说,直接解决问题
import os
import shutil
filelist
=[]
rootdir
=r
"G:\练习生\cxk"
filelist
=os
.listdir
(rootdir
)
for f
in filelist
:
filepath
= os
.path
.join
( rootdir
, f
)
if os
.path
.isfile
(filepath
):
os
.remove
(filepath
)
print(str(filepath
)+" removed!")
elif os
.path
.isdir
(filepath
):
shutil
.rmtree
(filepath
,True)
print("dir "+str(filepath
)+" removed!")
shutil
.rmtree
(rootdir
,True)
print("删除成功")
转载请注明原文地址: https://mac.8miu.com/read-487942.html