The remove method of os the module
The remove method deletes a file. In the method parameter, we specify the path to the file to be deleted. The method returns the value None. If the file to be deleted does not exist, then the FileNotFoundError exception is returned.
Syntax
import os
os.remove(path to file)
Example
Let's delete the file 'file.txt':
import os
os.remove('file.txt')
See also
-
method
makedirsof moduleos,
which creates folders -
method
mkdirof moduleos,
which creates one folder -
method
rmdirof moduleos,
which moves or deletes an empty folder -
method
renameof moduleos,
which renames a file and folder -
method
path.isfileof moduleos,
which checks the existence of a file -
method
copy2of moduleshutil,
which copies a file with metadata -
method
getcwdmoduleos,
which returns the current working directory -
method
listdirof moduleos,
which returns a list of files in the working directory