Languages
[Edit]
EN

Python - check if file exists

0 points
Created by:
Dale-K1
417

In this article, we would like to show you how to check if a file exists in Python.

Quick solution:

 

1. Using os.path.exists() method

Edit

In this example, we check if the file exists using exists() method from os.path module.

if the file isn't directly in our project we need to specify the path:

2. Using os.path.isfile() method

Edit

In this example, we check if the file exists using isfile() method from os.path module.

if the file isn't directly in our project we need to specify the path:

1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Python - file operations

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join