Is there a folder at a path?

EasyOS Module Programs · 12 of 49

Write a Python program to check whether a directory exists at a given path.

Advertisement
Output
data True
nowhere False
data/x.txt False

Approach

  1. os.path.isdir().

Solution

Python
import os os.makedirs("data", exist_ok=True)for p in ["data", "nowhere", "data/x.txt"]:    print(p, os.path.isdir(p))
Output
data True
nowhere False
data/x.txt 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