Check if File or Directory Exists using Python

os.path module

import os

pathname = 'dir/test.txt'
result = os.path.exists(pathname)

print(result)

Leave a Comment

Cancel reply

Your email address will not be published.