123 of 151 menu

The rmdir method of os the module

The rmdir method moves or deletes an empty folder. The first parameter of the method specifies the path to the folder, the second optional parameter is a file descriptor referring to the folder, its default value is None. The method returns None. If the folder being deleted does not exist, the FileNotFoundError exception is returned. If the specified folder contains files and subfolders, the method returns the OSError exception.

Syntax

import os os.rmdir(folder name, [file descriptor])

Example

Let's delete the folder dir1:

import os os.rmdir('dir1/')

See also

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