0
点赞
收藏
分享

微信扫一扫

【python基础】创建和删除目录

东言肆语 2023-04-29 阅读 63

前言

import os
import shutil
path='/home/tfl19671/out'
if not os.path.exists(path):
  os.mkdir(path)
else:
  shutil.rmtree(path, True)
  os.mkdir(path)

其中

shutil.rmtree(filepath,ignore_errors=True)
删除整个filepath路径的内容。
如果ignore_errors = True,则表示删除失败导致的错误将会被忽略;
如果ignore_errors = False,则表示删除失败时将会调用由onerrors指定的程序来处理此类错误;
如果忽略这一参数设定,删除失败时将会弹出一个exception。

 


举报

相关推荐

0 条评论