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.