pathlib – Check if file or folder exists

from pathlib import Path


full_path = Path(r"/home/documents/my_file.txt")

# Does the path exist?
# It could be a folder or file.
if full_path.exists():
    print("The path exists. It could be a folder or it could be a file.")

    # Is it a file?
    if full_path.is_file():
        print("It's a file")

    # Is it a directory?
    elif full_path.is_dir():
        print("It's a folder")

else:
   print("The path does not exist")