如何删除文件夹的内容?

如何删除文件夹的内容?,第1张

如何删除文件夹内容
import os, shutilfolder = '/path/to/folder'for filename in os.listdir(folder):    file_path = os.path.join(folder, filename)    try:        if os.path.isfile(file_path) or os.path.islink(file_path): os.unlink(file_path)        elif os.path.isdir(file_path): shutil.rmtree(file_path)    except Exception as e:        print('Failed to delete %s. Reason: %s' % (file_path, e))


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5649586.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存