mirror of
https://github.com/python/cpython.git
synced 2025-07-23 03:05:38 +00:00
Patch from Bastian Kleineidam <calvin@cs.uni-sb.de>: added 'remove_tree()'.
This commit is contained in:
parent
06537a5e89
commit
b98fe36c46
1 changed files with 20 additions and 1 deletions
|
@ -11,7 +11,7 @@ file causing it."""
|
||||||
|
|
||||||
__revision__ = "$Id$"
|
__revision__ = "$Id$"
|
||||||
|
|
||||||
import os, string
|
import os, string, shutil
|
||||||
from distutils.errors import *
|
from distutils.errors import *
|
||||||
|
|
||||||
|
|
||||||
|
@ -378,6 +378,25 @@ def copy_tree (src, dst,
|
||||||
# copy_tree ()
|
# 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!
|
# XXX I suspect this is Unix-specific -- need porting help!
|
||||||
def move_file (src, dst,
|
def move_file (src, dst,
|
||||||
verbose=0,
|
verbose=0,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue