Computer >> Computer tutorials >  >> Programming >> Python

How to delete a Python directory effectively?


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

 example

>>> 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')