Checking if a file or a directory exists with the Python language is straightforward; all you need is the os .path module and its built-in method exists().
Prerequisite:
Method definition:
os.path.exists(path)
# "path": path to the file or directory
# returns True if path refers to an existing path
The script:
import os
file = '/home/User/Desktop/test.txt'
dir = '/home/User/Desktop/'
fileExists = os.path.exists(file)
dirExists = os.path.exists(dir)
print(fileExists) # True
print(dirExists) # True