删除某路径下的所有文件

亲测好用

import os
import shutil
delList = []
delDir = '/root/data/V1.0/test/'
delList = os.listdir(delDir )
for f in delList:
    filePath = os.path.join( delDir, f )
    if os.path.isfile(filePath):
        os.remove(filePath)
        print (filePath + " was removed!")
    elif os.path.isdir(filePath):
        shutil.rmtree(filePath,True)
        print ("Directory: " + filePath +" was removed!")
发布了46 篇原创文章 · 获赞 9 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/weixin_43826596/article/details/100973336