YouTip LogoYouTip

Os Makedirs

# Python2.x Python os.makedirs() Method [![Image 3: Python File(Files) Method](#) Python OS File/Directory Methods](#) * * * ### Overview The os.makedirs() method is used to recursively create directories. If the subdirectory creation fails or already exists, an OSError exception will be thrown. On Windows, Error 183 indicates that the directory already exists. If the first parameter path has only one level, it is the same as the [mkdir()](#) function. ### Syntax The syntax for the **makedirs()** method is as follows: os.makedirs(path, mode=0o777) ### Parameters * **path** -- The directory to be created recursively, which can be a relative or absolute path. * **mode** -- Permission mode. ### Return Value This method does not return a value. ### Example The following example demonstrates the use of the makedirs() method: ## Example #!/usr/bin/python # -*- coding: UTF-8 -*- import os,sys # Directory to be created path ="/tmp/home/monthly/daily" os.makedirs( path,0755); print"Path created" The output of executing the above program is: Path created [![Image 4: Python File(Files) Method](#) Python OS File/Directory Methods](#)
← Os MakedirsOs Major β†’