Does a path exist?

EasyOS Module Programs · 46 of 49

Write a Python program to check whether a path exists.

Advertisement
Output
here.txt True
. True
nowhere False

Approach

  1. os.path.exists works for files and folders.

Solution

Python
import os open("here.txt", "w").close()for p in ["here.txt", ".", "nowhere"]:    print(p, os.path.exists(p))
Output
here.txt True
. True
nowhere False

Learn the concept

New to this topic? Read the lesson, then come back.

More os module programs

← All 49 OS Module Programs

Leave a Comment