def rmtree(path):
if islink(path):<EOL><INDENT>unlink(path)<EOL><DEDENT>elif os.path.isdir(path):<EOL><INDENT>for sub in os.listdir(path):<EOL><INDENT>sub = os.path.join(path, sub)<EOL>if os.path.isfile(sub):<EOL><INDENT>if not os.access(sub, os.W_OK):<EOL><INDENT>os.chmod(sub, stat.S_IWUSR)<EOL><DEDENT>os.unlink(sub)<EOL><DEDENT>else:<EOL><INDENT>rmtree(sub)<EOL><DEDENT><DEDENT>os.rmdir(path)<EOL><DEDENT>else:<EOL><INDENT>raise RuntimeError("<STR_LIT>")<EOL><DEDENT>
shutil.rmtree() but also handle junction points and access errors on Windows.