Delete a list of paths that are files or directories.
    If a file/directory does not exist, skip it.

    Arguments:
    ----------

    paths : list<str>, names of files/directories to remove.
179977
def delete_paths(paths):
    
    for path in paths:
        if exists(path):
            if isfile(path):
                remove(path)
            else:
                rmtree(path)
1029349
def filter_dirs(root, dirs, excl_paths):
    
    filtered_dirs = []
    for dirpath in dirs:
        abspath = os.path.abspath(os.path.join(root, dirpath))
        if os.path.basename(abspath) in _SKIP_DIRS:
            continue
        if abspath not in excl_paths:
            filtered_dirs.append(dirpath)
    return filtered_dirs
818743
def format_paths(paths, filepath)
      # Extract included paths
      paths
        .map { |path| File.join(File.dirname(filepath), path) }
        .map { |path| File.expand_path(path) }
        .select { |path| File.exist?(path) || Dir.exist?(path) }
    end
341510
def _recursive_remove_blank_dirs(self, path):
        
        path = os.path.abspath(path)

        # never delete root of the storage or smaller paths
        if path == self.path or len(path) <= len(self.path):
            return

        # if the path doesn't exists, go one level upper
        if not os.path.exists(path):
            return self._recursive_remove_blank_dirs(
                os.path.dirname(path)
            )

        # if the directory contains files, end yourself
        if os.listdir(path):
            return

        # blank directories can be removed
        shutil.rmtree(path)

        # go one level up, check whether the directory is blank too
        return self._recursive_remove_blank_dirs(
            os.path.dirname(path)
        )
694567
def safe_remove(path):
    
    if not os.path.exists(path):
        return

    try:
        if os.path.isdir(path) and not os.path.islink(path):
            shutil.rmtree(path)
        else:
            os.remove(path)
    except OSError:
        if os.path.exists(path):
            raise
366451
def __remove_path(self, path):
        
        curpath = os.path.abspath(os.curdir)
        if not os.path.exists(path):
            logger.warn("Attempted to remove a non-existent path %s" % path)
            return
        try:
            if os.path.islink(path):
                os.unlink(path)
            elif os.path.isdir(path):
                shutil.rmtree(path)
            else:
                os.unlink(path)

            # in the case we just deleted ourselves out of a valid directory,
            # we move to a valid directory.
            if curpath == path:
                os.chdir(tempfile.gettempdir())

        except OSError:
            logger.error("Unable to remove object at path %s" % path)
            raise DirectoryException("Unable to remove object at path %s" % path)
1289093
def clean(cls, path):
        ''''''
        for pth in os.listdir(path):
            pth = os.path.abspath(os.path.join(path, pth))
            if os.path.isdir(pth):
                logger.debug('Removing directory %s' % pth)
                shutil.rmtree(pth)
            else:
                logger.debug('Removing file %s' % pth)
                os.remove(pth)
1186184
def exit_if_path_not_found(path):
    
    if not os.path.exists(path):
        ui.error(c.MESSAGES["path_missing"], path)
        sys.exit(1)
636354
def delete_if_error(path):
    ''''''
    try:
        yield
    except Exception:
        if os.path.exists(path):
            os.remove(path)
        raise
846575
def delete_files(self, selections) -> None:
        """"""
        try:
            currentpath = self.currentpath
            for selection in selections:
                name = str(selection)
                if name == 'complete':
                    continue
                if not name.endswith('.py'):
                    name += '.py'
                path = os.path.join(currentpath, name)
                os.remove(path)
        except BaseException:
            objecttools.augment_excmessage(
                f'While trying to remove the network files of '
                f'selections `{selections}`')
1126455
def _remove_blacklisted(self, directories):
        
        directories = util.to_absolute_paths(directories)
        directories = util.remove_from_set(directories,
                                           self.blacklisted_directories)

        return directories
218299
def remove(path):
    

    try:
        if os.path.isfile(path):
            LOGGER.debug("> Removing '{0}' file.".format(path))
            os.remove(path)
        elif os.path.isdir(path):
            LOGGER.debug("> Removing '{0}' directory.".format(path))
            shutil.rmtree(path)
        return True
    except Exception as error:
        raise foundations.exceptions.PathRemoveError(
            "!> {0} | Cannot remove '{1}' path: '{2}'".format(__name__, path, error))
1133602
def remove(path):
    '''
    
    '''
    try:
        os.remove(path)
    except OSError as exc:
        if exc.errno != errno.ENOENT:
            raise
1333097
def clear_dir(path):
    """"""
    for f in os.listdir(path):
        f_path = os.path.join(path, f)
        if os.path.isfile(f_path) or os.path.islink(f_path):
            os.unlink(f_path)
320612
def remove_exts(self, exts):
        
        paths = []

        for ext in list_strings(exts):
            path = self.has_abiext(ext)
            if not path: continue
            try:
                os.remove(path)
                paths.append(path)
            except IOError:
                logger.warning("Exception while trying to remove file %s" % path)

        return paths
310257
def clean_caches(path):
    

    for dirname, subdirlist, filelist in os.walk(path):

        for f in filelist:
            if f.endswith('pyc'):
                try:
                    os.remove(os.path.join(dirname, f))
                except FileNotFoundError:
                    pass

        if dirname.endswith('__pycache__'):
            shutil.rmtree(dirname)
930372
def remove_if_exist(path):  # pragma: no cover
    """"""
    if os.path.exists(path):
        if os.path.isdir(path):
            shutil.rmtree(path)
            return True
        elif os.path.isfile(path):
            os.remove(path)
            return True
    return False