Given a directory, and a pattern of files like "garbage.txt" or
    "*pyc" inside it, remove them.

    Try not to delete the whole OS while you're at it.
324403
def remove_pattern(root, pat, verbose=True):
    
    print("removing pattern", root, pat)
    combined = root + pat
    print('combined', combined)
    items = glob.glob(combined)
    print('items', items)
    for item in items:
        print('item', item)
        if is_inside(root, item):
            remove(item)
        elif verbose:
            print("{item} is not inside {root}! Skipping.".format(**vars()))
1133602
def remove(path):
    '''
    
    '''
    try:
        os.remove(path)
    except OSError as exc:
        if exc.errno != errno.ENOENT:
            raise
210200
private void cleanDirectory(File dir) {
		if (isVerbose() || getLog().isDebugEnabled()) {
			getLog().info("Deleting previously generated files in directory: " + dir.getPath());
		}
		if (dir.exists()) {
			try {
				FileUtils.cleanDirectory(dir);
			} catch (IOException e) {
				getLog().warn("Cleaning directory failed: " + e.getMessage());
			}
		}
	}
1233161
def cleanup(temp_name):
    '''  '''
    for filename in iglob(temp_name + '*' if temp_name else temp_name):
        try:
            os.remove(filename)
        except OSError:
            pass
104573
def CleanUp(self, path):
    """"""
    try:
      if os.path.exists(path):
        os.remove(path)
    except (OSError, IOError) as e:
      logging.info("Failed to remove temporary file %s. Err: %s", path, e)
829779
def _delete_compiled_python_files():
    """"""
    for path, _, files in os.walk(os.getcwd()):
        for fname in [f for f in files if os.path.splitext(f)[1] == ".pyc"]:
            try:
                os.remove(os.path.join(path, fname))
            except OSError:
                pass
393037
def _clean_dir(root, keep, exclude_pat):
    '''
    
    '''
    root = os.path.normcase(root)
    real_keep = _find_keep_files(root, keep)
    removed = set()

    def _delete_not_kept(nfn):
        if nfn not in real_keep:
            # -- check if this is a part of exclude_pat(only). No need to
            # check include_pat
            if not salt.utils.stringutils.check_include_exclude(
                    os.path.relpath(nfn, root), None, exclude_pat):
                return
            removed.add(nfn)
            if not __opts__['test']:
                try:
                    os.remove(nfn)
                except OSError:
                    __salt__['file.remove'](nfn)

    for roots, dirs, files in salt.utils.path.os_walk(root):
        for name in itertools.chain(dirs, files):
            _delete_not_kept(os.path.join(roots, name))
    return list(removed)
1034359
def cleanup():
    """"""
    if _output_dir and os.path.exists(_output_dir):
        log.msg_warn("Cleaning up output directory at '{output_dir}' ..."
                     .format(output_dir=_output_dir))
        if not _dry_run:
            shutil.rmtree(_output_dir)
197483
def prune(self, dir):
        """"""
        match = translate_pattern(os.path.join(dir, '**'))
        return self._remove_files(match.match)
1228608
def remove_files(root_dir):
    
    for dirpath, dirnames, filenames in os.walk(os.path.abspath(root_dir)):
        for filename in filenames:
            os.remove(os.path.join(root_dir, filename))

        for dirname in dirnames:
            shutil.rmtree(os.path.join(root_dir, dirname))
550889
def remove_file(paths):
    

    for path in force_list(paths):
        if os.path.exists(path):
            os.remove(path)
545549
def rm_file_or_dir(path, ignore_errors=True):
    
    if os.path.exists(path):
        if os.path.isdir(path):
            if os.path.islink(path):
                os.unlink(path)
            else:
                shutil.rmtree(path, ignore_errors=ignore_errors)
        else:
            if os.path.islink(path):
                os.unlink(path)
            else:
                os.remove(path)
201882
def cleanup(self):
        ""
        log.info('Removing temp dir %s', self._tempdir.name)
        self._tempdir.cleanup()
55725
def remove_files(filename):
        # type: (AnyStr) -> None
        
        pattern = os.path.splitext(filename)[0] + '.*'
        for f in glob.iglob(pattern):
            os.remove(f)
724602
def clean_directories(builddir, in_dir=True, out_dir=True):
    """"""
    container_in = local.path(builddir) / "container-in"
    container_out = local.path(builddir) / "container-out"

    if in_dir and container_in.exists():
        if ui.ask("Should I delete '{0}'?".format(container_in)):
            container_in.delete()
    if out_dir and container_out.exists():
        if ui.ask("Should I delete '{0}'?".format(container_out)):
            container_out.delete()
147703
def _remove_old_stderr_files(self):
        
        if os.name == 'nt':
            tmpdir = get_temp_dir()
            for fname in os.listdir(tmpdir):
                if osp.splitext(fname)[1] == '.stderr':
                    try:
                        os.remove(osp.join(tmpdir, fname))
                    except Exception:
                        pass
609297
def clean(self):
        
        if not util.is_blank(self.catalog.catname) and os.path.exists(self.catalog.catname):
            os.remove(self.catalog.catname)