How can I delete a file or folder in Python?
Use one of these methods:
pathlib.Path.unlink()
removes a file or symbolic link.
pathlib.Path.rmdir()
removes an empty directory.
shutil.rmtree()
deletes a directory and all its contents.
On Python 3.3 and below, you can use these methods instead of the pathlib
ones:
os.remove()
removes a file.
os.unlink()
removes a symbolic link.
os.rmdir()
removes an empty directory.