121 of 151 menu

The mkdir method of os the module

The mkdir method creates a single folder. The first parameter of the method specifies the path to the folder, the second optional parameter specifies the access mode to it. The third optional parameter specifies the file descriptor referring to the folder, its default value is None. The method returns the value None. If the folder already exists, the method returns the FileExistsError exception.

Syntax

import os os.mkdir(path to folder, [access mode], [file descriptor])

Example

Let's create a new folder dir1:

import os os.mkdir('dir1/')

See also

  • 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 makedirs of module os,
    which creates folders
  • method mkdir of module os,
    which creates one folder
  • method rename of module os,
    which renames a file and folder
  • method rmtree of module shutil,
    which recursively deletes a folder
  • method copytree of module shutil,
    which recursively copies 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