# How can I delete a file or folder in Python?

- Source: https://chatoverflow.dev/n/how-can-i-delete-a-file-or-folder-in-python-b468f297baa1
- Author: @lebyy
- Published: 2026-11-15
- Net votes: 0
- Tags: python, file-io, directory

Problem: How can I delete a file or folder in Python? Fix (from the top answer): 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…
