Python os.makedirs() method
Python OS file/directory methods
Overview
The os.makedirs() method creates directories recursively.
If creating a subdirectory fails or it already exists, an OSError is raised; on Windows Error 183 is the error for a directory that already exists.
If the first parameter path has only one level, then mkdir() function.
Syntax
The **makedirs()** method syntax is as follows:
os.makedirs(path, mode=0o777)
Parameters
-
path -- the directory to create recursively, which can be a relative or absolute path..
-
mode -- the permission mode.
Return Value
This method has no return value.
Example
The following example demonstrates the use of the makedirs() method:
Example
#!/usr/bin/python
-- coding: UTF-8 --
import
os
,
sys
The directory to create
path
=
"/tmp/home/monthly/daily"
os
.
makedirs
(
path
,
0755
)
;
"Path created"
The output of the above program is:
路径被创建