os.makedirs() Method in Python

os.makedirs() method in Python is used to create a directory recursively. That means while making leaf directory if any intermediate-level directory is missing, os.makedirs() method will create them all.

For example, consider the following path:

/home/User/Documents/w3wiki/Authors/ihritik

Suppose we want to create directory ‘ihritik’ but Directory ‘w3wiki’ and ‘Authors’ are unavailable in the path. Then os.makedirs() method will create all unavailable/missing directory in the specified path. ‘w3wiki’ and ‘Authors’ will be created first then ‘ihritik’ directory will be created.

Python | os.makedirs() method

All functions in the os module raise OSError in the case of invalid or inaccessible file names and paths, or other arguments that have the correct type but are not accepted by the operating system. In this article, we will see how to create directories recursively using the os module and also about os.makedirs() method.

Similar Reads

Python os.makedirs() Function Syntax

Syntax: os.makedirs(path, mode = 0o777, exist_ok = False)  Parameter:  path: A path-like object representing a file system path. A path-like object is either a string or bytes object representing a path. mode (optional) : A Integer value representing mode of the newly created directory..If this parameter is omitted then the default value Oo777 is used. exist_ok (optional) : A default value False is used for this parameter. If the target directory already exists an OSError is raised if its value is False otherwise not. For value True leaves directory unaltered.  Return Type: This method does not return any value....

os.makedirs() Method in Python

os.makedirs() method in Python is used to create a directory recursively. That means while making leaf directory if any intermediate-level directory is missing, os.makedirs() method will create them all....

Python os.makedirs() Function Examples

Below are some examples of os.makedirs() function by which we can see how to create directories recursively using the os module:...

Contact Us