[Python] Delete the entire folder or file

0. Environment

windows
python3.6

1. Delete the entire folder

import shutil
your_want_rm_path = “E:/data/1/”
shutil.rmtree(your_want_rm_path, ignore_errors=True)

2. Delete files

import os
old_file = “E:/data/1/1.txt”
os.remove(old_file)

 

Guess you like

Origin blog.csdn.net/qq_35975447/article/details/110195286