Python 3 - os.mkdir() Method


Description

The method mkdir() create a directory named path with numeric mode mode. The default mode is 0777 (octal). On some systems, mode is ignored. Where it is used, the current umask value is first masked out.

Syntax

Following is the syntax for mkdir() method −

os.mkdir(path[, mode])

Parameters

  • path − This is the path, which needs to be created.

  • mode − This is the mode of the directories to be given.

Return Value

This method does not return any value.

Example

The following example shows the usage of mkdir() method.

#!/usr/bin/python3
import os, sys

# Path to be created
path = "/tmp/home/monthly/daily/hourly"
os.mkdir( path, 0755 )

print ("Path is created")

Result

When we run the above program, it produces the following result −

Path is created
python_files_io.htm
Advertisements