Python Practice › OS Module Programs › Program 5
Create a directory with os.mkdir()
Write a Python program to create a directory with os.mkdir().
Output
True
Approach
os.mkdir()creates one folder; it fails if it already exists.
Solution
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.