The Python .rmdir() method allows the user to delete a folder if it exists in the system or computer and does not contain other folders or files.

Note: A FileNotFoundError is raised if the directory is not found.


This method is provided by the os module which must be imported beforehand.

import os



The .rmdir() method works in the following ways:

  • A "folder_name" that will be successfully deleted if the folder exists in the current directory.
  • A "folder_path" can also be passed if it exists outside of the current directory.

Files can be removed using the .remove() method.


Use .rmdir() to delete the myfolder folder:

import os
# Delete folder in current directory
# Delete folder in another directory

All contributors

Looking to contribute?

Learn Python on Codecademy