Latest web development tutorials

Python os.makedirs () method

Python File (File) method Python OS file / directory methods


Outline

os.makedirs () method is used to create directories recursively. Like mkdir (), but all intermediate-level folders that you create needs to include subdirectories.

grammar

makedirs () method syntax is as follows:

os.makedirs(path, mode=0o777)

parameter

  • path - the directory recursively created.

  • mode - Permissions mode.

return value

This method has no return value.

Examples

The following example demonstrates makedirs () method of use:

#!/usr/bin/python
# -*- coding: UTF-8 -*-

import os, sys

# 创建的目录
path = "/tmp/home/monthly/daily"

os.makedirs( path, 0755 );

print "路径被创建"

The above program output is:

路径被创建

Python File (File) method Python OS file / directory methods