Remove the given recursively.

    :note: we use shutil rmtree but adjust its behaviour to see whether files that
        couldn't be deleted are read-only. Windows will not remove them in that case
357966
def rmtree(path):
    """"""

    def onerror(func, path, exc_info):
        # Is the error an access error ?
        os.chmod(path, stat.S_IWUSR)

        try:
            func(path)  # Will scream if still not possible to delete.
        except Exception as ex:
            if HIDE_WINDOWS_KNOWN_ERRORS:
                raise SkipTest("FIXME: fails with: PermissionError\n  %s", ex)
            else:
                raise

    return shutil.rmtree(path, False, onerror)
275946
def rm(path, recursive=False):
    
    try:
        if recursive:
            if os.path.isfile(path):
                os.remove(path)
            else:
                shutil.rmtree(path)
        else:
            if os.path.isfile(path):
                os.remove(path)
            else:
                os.rmdir(path)
    except OSError as error:
        log.error('rm: execute failed: %s (%s)' % (path, error))
        return False
    return True
991592
def cleanup(output_root):
    """"""
    if os.path.exists(output_root):
        if os.path.isdir(output_root):
            rmtree(output_root)
        else:
            os.remove(output_root)
163515
def remove(self, iterable, data=None):
        
        return self.root.remove(iterable, data=data)
647817
def prune_tree(path):
    
    try:
        os.unlink(path)
        return
    except OSError:
        e = sys.exc_info()[1]
        if not (os.path.isdir(path) and
                e.args[0] in (errno.EPERM, errno.EISDIR)):
            LOG.error('prune_tree(%r): %s', path, e)
            return

    try:
        # Ensure write access for readonly directories. Ignore error in case
        # path is on a weird filesystem (e.g. vfat).
        os.chmod(path, int('0700', 8))
    except OSError:
        e = sys.exc_info()[1]
        LOG.warning('prune_tree(%r): %s', path, e)

    try:
        for name in os.listdir(path):
            if name not in ('.', '..'):
                prune_tree(os.path.join(path, name))
        os.rmdir(path)
    except OSError:
        e = sys.exc_info()[1]
        LOG.error('prune_tree(%r): %s', path, e)
123815
def remove(self):
        # type: () -> int
        
        removes = 0
        for path, info in self._make_iter(search="depth"):
            if info.is_dir:
                self.fs.removetree(path)
            else:
                self.fs.remove(path)
            removes += 1
        return removes
1087594
def delete_directories(paths):
    
    for path in paths:
        if os.path.exists(path):
            shutil.rmtree(path)
913365
def clear_cache(self):
        '''
        
        '''
        errors = []
        for rdir in (self.cache_root, self.file_list_cachedir):
            if os.path.exists(rdir):
                try:
                    shutil.rmtree(rdir)
                except OSError as exc:
                    errors.append(
                        'Unable to delete {0}: {1}'.format(rdir, exc)
                    )
        return errors
315389
def remove(item):
    
    if os.path.isdir(item):
        shutil.rmtree(item)
    else:
        # Assume it's a file. error if not.
        os.remove(item)
1132852
def remove(path, **kwargs):
    '''
    
    '''
    path = os.path.expanduser(path)

    if not os.path.isabs(path):
        raise SaltInvocationError('File path must be absolute: {0}'.format(path))

    try:
        if os.path.isfile(path) or os.path.islink(path):
            os.remove(path)
            return True
        elif os.path.isdir(path):
            shutil.rmtree(path)
            return True
    except (OSError, IOError) as exc:
        raise CommandExecutionError(
            'Could not remove \'{0}\': {1}'.format(path, exc)
        )
    return False
1230067
def rmnode(path: str):
    """"""
    if isdir(path):
        rmtree(path)
    elif isfile(path):
        os.remove(path)
1360299
def remove_entry(self, fs_entry):
        
        try:
            self._root_elements.remove(fs_entry)
        except ValueError:  # fs_entry may not be in the root elements
            pass
        if fs_entry.parent:
            fs_entry.parent.remove_child(fs_entry)
        # Reset file lists so they get regenerated without the removed file(s)
        self._all_files = None
138974
def remove_folder_content(path, ignore_hidden_file=False):
    
    for file in os.listdir(path):
        if ignore_hidden_file and file.startswith('.'):
            continue

        file_path = os.path.join(path, file)
        if os.path.isdir(file_path):
            shutil.rmtree(file_path)
        else:
            os.remove(file_path)
793416
def delete_dir_rec(path: Path):
    
    if not path.exists() or not path.is_dir():
        return
    for sub in path.iterdir():
        if sub.is_dir():
            delete_dir_rec(sub)
        else:
            sub.unlink()
    path.rmdir()
1276650
def removed_tree(self, dirname):
        """"""
        dirname = osp.abspath(to_text_string(dirname))
        for fname in self.get_filenames():
            if osp.abspath(fname).startswith(dirname):
                self.close_file_from_name(fname)
1077897
def rmtree_glob(file_glob):
    """"""
    for item in glob(file_glob, recursive=True):
        try:
            os.remove(item)
            print('%s removed ...' % item)
        except OSError:
            try:
                shutil.rmtree(item)
                print('%s/ removed ...' % item)
            except OSError as err:
                print(err)
1204315
def remove_file(file_path):
    """"""
    if path.exists(file_path):
        try:
            rmtree(file_path)
        except Exception:
            print('Unable to remove temporary workdir {}'.format(file_path))