How to delete a Python directory effectively?

PythonServer Side ProgrammingProgramming

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


>>> import os
>>> os.rmdir('my_folder')

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')
Published on 27-Dec-2017 11:44:35