122 of 151 menu

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 mkdir of module os,
    which creates one folder
  • method remove of module os,
    which deletes the file
  • method getcwd module os,
    which returns the current working directory
  • method listdir of module os,
    which returns a list of files in the working directory
  • method rmdir of module os,
    which moves or deletes an empty folder
  • method rename of module os,
    which renames a file and folder
  • method scandir of module os,
    which iterates through the files in a folder
English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline