python 删除本地文件兼容windows和linux

def del_local_file(file_pth, is_dir=False):
sysstr = platform.system()
# 删除本地文件
if not is_dir:
if sysstr == "Windows":
os.system('del /s/q %s' % file_pth)
elif sysstr == "Linux":
os.system('rm -rf %s' % file_pth)
else:
if sysstr == "Windows":
os.system('rd /s/q %s' % file_pth)
elif sysstr == "Linux":
os.system('rm -rf %s' % file_pth)
posted @ 2021-03-31 16:37  你看起来真的很好吃  阅读(178)  评论(0编辑  收藏  举报