def rmtree(dirname):
 excs = []
 try:
  os.chmod(dirname, ((stat.S_IWRITE | stat.S_IEXEC) | stat.S_IREAD))
  for f in os.listdir(dirname):
   fullname = os.path.join(dirname, f)
   if os.path.isdir(fullname):
    rm_dir(fullname)
   else:
    remove(fullname)
  os.rmdir(dirname)
 except EnvironmentError as le:
  if (((le.args[0] != 2) and (le.args[0] != 3)) or (le.args[0] != errno.ENOENT)):
   excs.append(le)
 except Exception as le:
  excs.append(le)
 if os.path.exists(dirname):
  if (len(excs) == 1):
   raise excs[0]
  if (len(excs) == 0):
   raise OSError, 'Failed to remove dir for unknown reason.'
  raise OSError, excs

def rmtree ( dirname ) : excs = [ ] try : os . chmod ( dirname , ( ( stat . S_IWRITE | stat . S_IEXEC ) | stat . S_IREAD ) ) for f in os . listdir ( dirname ) : fullname = os . path . join ( dirname , f ) if os . path . isdir ( fullname ) : rm_dir ( fullname ) else : remove ( fullname ) os . rmdir ( dirname ) except EnvironmentError as le : if ( ( ( le . args [ 0 ] != 2 ) and ( le . args [ 0 ] != 3 ) ) or ( le . args [ 0 ] != errno . ENOENT ) ) : excs . append ( le ) except Exception as le : excs . append ( le ) if os . path . exists ( dirname ) : if ( len ( excs ) == 1 ) : raise excs [ 0 ] if ( len ( excs ) == 0 ) : raise OSError , 'Failed to remove dir for unknown reason.' raise OSError , excs
recursively delete a directory tree .