How to remove a directory using Python?

PythonServer Side ProgrammingProgramming

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

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 22-Dec-2017 10:01:56
Advertisements