The makedirs method of the os module
The makedirs method creates folders recursively, i.e. one folder will contain other subfolders. The first parameter of the method specifies the path to the folders, the second optional parameter specifies the access mode to them, and the third optional parameter specifies error management (by default exist_ok=False). The method returns the value None.
Syntax
import os
os.makedirs(path to folders, [access mode], [error management])
Example
Let's create a new folder with nested subfolders along the path dir/tst/new:
import os
os.makedirs('dir/tst/new')
See also
-
method
mkdirof moduleos,
which creates one folder -
method
removeof moduleos,
which deletes the file -
method
getcwdmoduleos,
which returns the current working directory -
method
listdirof moduleos,
which returns a list of files in the working directory -
method
rmdirof moduleos,
which moves or deletes an empty folder -
method
renameof moduleos,
which renames a file and folder -
method
scandirof moduleos,
which iterates through the files in a folder