Python os.mkdir() Method
Example
Create a directory:
#Import os Library
import os
# Create Directory
os.mkdir("c:/test/w3school")
Definition and Usage
The os.mkdir()
method is used to create a directory.
If the directory already exists, FileExistsError
is raised
Note: Available on WINDOWS and UNIX platforms.
Syntax
os.mkdir(path, mode, dir_fd)
Parameter Values
Parameter | Description |
---|---|
path | Required. A path-like object representing a file system path. The path-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 . |
dir_fd | Optional. A file descriptor referring to a directory. The default value is None |
Technical Details
Return Value: | None |
---|---|
Python Version: | 1.5.2 |
Change Log: | 3.3 - Added the dir_fd parameter 3.6 - Accepts a path-like object |