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
rmtreeof moduleshutil,
which recursively deletes a folder -
method
mkdirof moduleos,
which creates one folder -
method
makedirsof moduleos,
which creates folders -
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