{"id":5669,"date":"2021-05-16T10:44:19","date_gmt":"2021-05-16T05:14:19","guid":{"rendered":"https:\/\/python-programs.com\/?p=5669"},"modified":"2021-11-22T18:40:51","modified_gmt":"2021-11-22T13:10:51","slug":"python-how-to-delete-a-directory-recursively-using-shutil-rmtree","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-how-to-delete-a-directory-recursively-using-shutil-rmtree\/","title":{"rendered":"Python : How to delete a directory recursively using shutil.rmtree()"},"content":{"rendered":"

How to delete a directory recursively using shutil.rmtree() in Python ?<\/h2>\n

In this article, we will discuss about how we can delete an empty directory and also all contents of a directory including sub directories using shutil.rmtree().<\/p>\n

Delete an empty directory using os.rmdir() :<\/h3>\n

The os module of python provide a function i.e. os.rmdir(pathOfDir)<\/code> which can delete an empty directory. It can also give rise to certain errors in some scenarios like:<\/p>\n