← Go Back
Note that when giving a path, all intermediate folders must exist. For example, in the second case, the function would raise
How to Create a Directory or Folder
Theos.mkdir()
standard function takes the name of (or a path to) a non-existent directory and creates it in the file system.from os import mkdir
# Create the "new folder" directory inside the current directory.
mkdir("new folder")
# Create the "new folder" directory inside /home/user/documents.
mkdir("/home/user/documents/new folder")
Note that when giving a path, all intermediate folders must exist. For example, in the second case, the function would raise
FileNotFoundError
if any of home
, user
or documents
do not exist.🐍 You might also find interesting: