How are entire non-empty directory trees removed using Python?

PythonServer Side ProgrammingProgramming

If you want to delete a folder containing all files you want to remove, you can remove the folder as follows −

>>> import shutil
>>> shutil.rmtree('my_folder')

If you want to remove an empty folder, you can call the rmdir function in os module. For example,

>>> import os
>>> os.rmdir('my_folder')
Published on 28-Dec-2017 06:34:50