[Python-Dev] os.removedirs() vs. shutil.rmtree() (original) (raw)

Johannes Gijsbers jlg at dds.nl
Sat Jan 8 22:05:29 CET 2005


On Sat, Jan 08, 2005 at 02:45:25PM -0600, Skip Montanaro wrote:

Is there a reason the standard library needs both os.removedirs and shutil.rmtree? They seem awful similar to me (I can see they aren't really identical). Ditto for os.renames and shutil.move. Presuming they are all really needed, is there some reason they don't all belong in the same module?

os.removedirs() only removes directories, it will fail to remove a non-empty directory, for example. It also doesn't have the ignore_errors/onerror arguments [1]. os.renames() is different from shutil.move() in that it also creates intermediate directories (and deletes any left empty).

So they're not identical, but I do agree they should be consolidated and moved into one module. I'd say shutil, both because the os module is already awfully crowded, and because these functions are "high-level operations on files and collections of files" rather than "a more portable way of using operating system dependent functionality [...]".

Johannes

[1] That may actually be a good thing, though. It was a pain to keep those working backwards-compatibly when shutil.rmtree was recently rewritten.



More information about the Python-Dev mailing list