Use “path.exists” method of os library to check if file or directory exists for a path

Code to Check if file or directory exists

# Imports
from os.path import exists, join
from os import getcwd
# Let's get current path
path = getcwd()
# How to check if a given directory or file exists
print(exists(path))
True
# True because above directory exists
# Now let's check for a file which doesn't exist
path = join(path, 'notpresent.abcd')
print(exists(path))
False

That's how we Check if a File or Directory exists