How To Check Whether A File Exists Using Python?

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/check-whether-file-exists-using-python/
PINTEREST
PINTEREST
INSTAGRAM

Python programming language provides different ways to check file existence. In this tutorial we will examine functions like isFile() and exists() to check file existence.

Import os.path Module

In order to use isFile() and exists() functions we need to import the os.path module which contains these functions.

isFile() Method

isfile() is a function in os.path library. This function will be return true if the file is regular file and exists. As we can see following example we should provide the path and name of the file.

isFile() Method
isFile() Method

exists() Method

exists is os.path method too and returns true if file exists. We will provide /etc/passwd as parameter to the exists() function like below.

exists() Method
exists() Method

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/check-whether-file-exists-using-python/
PINTEREST
PINTEREST
INSTAGRAM
LEARN MORE  How To Setup C Development Environment