如何在Python中删除文件或文件夹?
os.remove() removes a file. (os.remove()删除文件。)
os.remove()
os.rmdir() removes an empty directory. (os.rmdir()删除一个空目录。)
os.rmdir()
shutil.rmtree() deletes a directory and all its contents. (shutil.rmtree()删除目录及其所有内容。)
shutil.rmtree()
Path objects from the Python 3.4+ pathlib module also expose these instance methods: (Python 3.4+ pathlib模块中的Path对象也公开了这些实例方法:)
Path
pathlib
pathlib.Path.unlink() removes a file or symbolic link. (pathlib.Path.unlink()删除文件或符号链接。)
pathlib.Path.unlink()
pathlib.Path.rmdir() removes an empty directory. (pathlib.Path.rmdir()删除一个空目录。)
pathlib.Path.rmdir()
2.1m questions
2.1m answers
60 comments
57.0k users