Create a directory with os.mkdir()

EasyOS Module Programs · 5 of 49

Write a Python program to create a directory with os.mkdir().

Advertisement
Output
True

Approach

  1. os.mkdir() creates one folder; it fails if it already exists.

Solution

Python
import os if not os.path.exists("reports"):    os.mkdir("reports")print(os.path.isdir("reports"))
Output
True

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