summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Ward <gward@python.net>2000-03-18 15:42:22 (GMT)
committerGreg Ward <gward@python.net>2000-03-18 15:42:22 (GMT)
commitb98fe36c46e48e30decd6b844ed48446c51d303a (patch)
tree05e05f19ddd81d14b5b854d48c5c03b703020ef9
parent06537a5e899dff16939c31ba66a196735973dc74 (diff)
downloadcpython-b98fe36c46e48e30decd6b844ed48446c51d303a.zip
cpython-b98fe36c46e48e30decd6b844ed48446c51d303a.tar.gz
cpython-b98fe36c46e48e30decd6b844ed48446c51d303a.tar.bz2
Patch from Bastian Kleineidam <calvin@cs.uni-sb.de>: added 'remove_tree()'.
-rw-r--r--Lib/distutils/util.py21
1 files changed, 20 insertions, 1 deletions
diff --git a/Lib/distutils/util.py b/Lib/distutils/util.py
index 2f193fb..7a07b65 100644
--- a/Lib/distutils/util.py
+++ b/Lib/distutils/util.py
@@ -11,7 +11,7 @@ file causing it."""
__revision__ = "$Id$"
-import os, string
+import os, string, shutil
from distutils.errors import *
@@ -378,6 +378,25 @@ def copy_tree (src, dst,
# copy_tree ()
+def remove_tree (directory, verbose=0, dry_run=0):
+ """Recursively remove an entire directory tree. Any errors are ignored
+ (apart from being reported to stdout if 'verbose' is true)."""
+
+ if verbose:
+ print "removing '%s' (and everything under it)" % directory
+ if dry_run:
+ return
+ try:
+ shutil.rmtree(directory,1)
+ except (IOError, OSError), exc:
+ if verbose:
+ if exc.filename:
+ print "error removing %s: %s (%s)" % \
+ (directory, exc.strerror, exc.filename)
+ else:
+ print "error removing %s: %s" % (directory, exc.strerror)
+
+
# XXX I suspect this is Unix-specific -- need porting help!
def move_file (src, dst,
verbose=0,