Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python
mkdir
os

What is the Python mkdir method?

Educative Answers Team

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

svg viewer

Os.mkdir() method is used in python to try to create a path with a numeric mode.

Note: The method gives FileExistsError if the path already exists.

Here is the syntax for the mkdir method:

os.mkdir(path[,mode])

  • path is the path where you want to complete the new directory.
  • mode is the mode of the directory to be given. The default mode is 0777(octal)0777 (octal).

In some systems, the mode parameter is ignored, which​ sets the current umask value.

Here is the complete implementation using default mode.

# import library
import os
# this is the directory that will be created
path = "/home/User/Downloads/myfolder"
#use os.mkdir() to create the directory
os.mkdir(path)

The official documentation can be found here.

RELATED TAGS

python
mkdir
os
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring