Python3 os.mkdir() Method
Python3 OS File/Directory Methods
Overview
The os.mkdir() method is used to create a directory with a numeric permission mode. The default mode is 0777 (octal).
If the directory has multiple levels, only the last level is created. If any parent directory of the last level does not exist, an OSError will be raised.
Syntax
mkdir()The method syntax is as follows:
os.mkdir(path[, mode])
Parameters
path-- The directory to be created, which can be a relative or absolute path.
mode-- The numeric permission mode to be set for the directory.
Return Value
This method has no return value.
Example
The following example demonstrates the use of the mkdir() method:
Example
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import os, sys
# The directory to be created
path = "/tmp/home/monthly/daily/hourly"
os.mkdir( path, 0755 )
print ("Directory created")
# -*- coding: UTF-8 -*-
import os, sys
# The directory to be created
path = "/tmp/home/monthly/daily/hourly"
os.mkdir( path, 0755 )
print ("Directory created")
After executing the above program, the output result is:
Directory createdOther Extensions