.unlink() file method allows the user to delete a file path if it exists in the system or computer.
.remove() is the alternative to delete a specific file.
FileNotFoundError is raised if the file is not found or isn’t in the current directory.
This method is provided by the
os module which must be imported beforehand.
import os os.unlink("file_path")
Entire folders or directories can be removed using the
.unlink() to delete the
import os# Delete file pathos.unlink("path/to/my_file.txt")
In this example
delete_me.txt is deleted using the complete file path and the
- Anonymous contributorAnonymous contributor3 total contributions
- Anonymous contributorAnonymous contributor9 total contributions
- Anonymous contributorAnonymous contributor15 total contributions
- Christine_Yang271 total contributions