def rmtree(path, ignore_errors=False, onerror=auto_chmod):
if ignore_errors:<EOL><INDENT>def onerror(*args):<EOL><INDENT>pass<EOL><DEDENT><DEDENT>elif onerror is None:<EOL><INDENT>def onerror(*args):<EOL><INDENT>raise<EOL><DEDENT><DEDENT>names = []<EOL>try:<EOL><INDENT>names = os.listdir(path)<EOL><DEDENT>except os.error:<EOL><INDENT>onerror(os.listdir, path, sys.exc_info())<EOL><DEDENT>for name in names:<EOL><INDENT>fullname = os.path.join(path, name)<EOL>try:<EOL><INDENT>mode = os.lstat(fullname).st_mode<EOL><DEDENT>except os.error:<EOL><INDENT>mode = <NUM_LIT:0><EOL><DEDENT>if stat.S_ISDIR(mode):<EOL><INDENT>rmtree(fullname, ignore_errors, onerror)<EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>os.remove(fullname)<EOL><DEDENT>except os.error:<EOL><INDENT>onerror(os.remove, fullname, sys.exc_info())<EOL><DEDENT><DEDENT><DEDENT>try:<EOL><INDENT>os.rmdir(path)<EOL><DEDENT>except os.error:<EOL><INDENT>onerror(os.rmdir, path, sys.exc_info())<EOL><DEDENT>
Recursively delete a directory tree.

    This code is taken from the Python 2.4 version of 'shutil', because
    the 2.3 version doesn't really work right.