Python os.makedirs() Method
Example
Create a recursive directory:
#Import os Library
import os
# Create Directory
os.makedirs("c:/test/w3school")
Definition and Usage
The os.makedirs()
method creates a directory
recursively.
While making directories if any intermediate directory is missing, os.makedirs()
method will create them all.
Syntax
os.makedirs(name, mode, exist_ok)
Parameter Values
Parameter | Description |
---|---|
name | Required. A name-like object representing file system path. The name-like object is either a string or bytes object representing a path |
mode | Optional. An integer value representing permission of the newly-created directory. The default value is Oo777 . |
exist_ok | Optional. Default value of this parameter is False. If the specified directory already exists and value is set to False an OSError is raised, else not. |
Technical Details
Return Value: | None |
---|---|
Python Version: | 1.5.2 |
Change Log: | 3.2 - Added the exist_ok parameter |