[Tutor] removedirs ?

Kent Johnson kent37 at tds.net
Thu Dec 16 21:50:23 CET 2004

You misunderstand what removedirs does. It removes an empty directory; then, if the removed 
directory's parent is now empty, it removes that, too, and so on until it finds a directory with 
something in it or gets up to the root.

Try shutil.rmtree() or this recipe:


Ertl, John wrote:
> I am trying to remove a directory that has other directories and files in
> it.  I thought removedirs was supposed to do a recursive remove of files and
> directories.
> When I try it I get 
> Traceback (most recent call last):
>   File "<pyshell#11>", line 1, in -toplevel-
>     os.removedirs("DAF")
>   File "/home/ertlj/ertljVersion/lib/python2.3/os.py", line 167, in
> removedirs
>     rmdir(name)
> OSError: [Errno 17] File exists: 'DAF'
> Thanks,
> John Ertl

More information about the Tutor mailing list