Created
March 7, 2019 10:47
-
-
Save ayuLiao/bffe59e2afb179ef81dfce85b2958b49 to your computer and use it in GitHub Desktop.
python删除文件或目录
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#删除文件 | |
os.remove(my_file) | |
# 删除目录 path,要求path必须是个空目录,否则抛出OSError错误 | |
os.rmdir(path) | |
# 删除目录 path, path不需要为空目录,该方法不能删除文件 | |
import shutil | |
shutil.rmtree(path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment