Thursday, October 25, 2012

Use shutil.rmtree for deleting whole directory

Maybe, one tries to use os.remove(path) or os.removedirs(path) for deleting the whole directory.

However, they should raise an error when the directory is not empty. So, the better choice is using shutil.rmtree(path).

The name remove tree fits the idea of removing everything whereas remove and removedir delete the directory (only the directory not files in it).

No comments:

Post a Comment