Last updated on August 8, 2022
In this tutorial, you will learn how to delete a file using the Python programing language. Deleting files using Python is very simple. You can delete files using the os.remove()
method. You can delete a file using both relative path and absolute path. Below is the example code.
Remove file with relative path
import os
# removing a file with relative path
os.remove("file_1.txt")
Remove file with absolute path
import os
# remove file with absolute path
os.remove(r"c:\test\file_2.txt")
Comments are closed, but trackbacks and pingbacks are open.