The Python .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.

Note: A 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


Entire folders or directories can be removed using the .rmdir() method.


Use .unlink() to delete the my_file.txt file:

import os
# Delete file path

All contributors

Looking to contribute?

Learn Python on Codecademy