# Python, how to check if a file or directory exists

> Learn how to check if a file or directory exists in Python using the os.path.exists() method, which returns True if the path exists and False if it does not.

Author: [Flavio Copes](https://flaviocopes.com/about/) | Published: 2021-01-25 | Topics: [Python](https://flaviocopes.com/tags/python/) | Canonical: https://flaviocopes.com/python-check-file-exists/

The `os.path.exists()` method provided by the `os` standard library module returns `True` if a file exists, and `False` if not.

Here is how to use it:

```python
import os

filename = '/Users/flavio/test.txt'

exists = os.path.exists(filename)

print(exists) # True
```
