For removing/deleting any folder that is not empty with Python we have a standard library which is known as shutil. This library provides the function shutil.rmtree() which removes/deletes the non-empty folder.
This function deletes an entire directory tree; the path that must point to a directory (but not a symbolic link to a directory) such kind of errors are handled by calling a handler specified by raising an exception.
The following code illustrates the use of the shutil library and shutil.rmtree() function:-
For more information, kindly refer to our Python course.