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. 

 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')
raja
Published on 27-Dec-2017 07:14:35
Advertisements