Apply the include and exclude filters to those files in *unmatched*,
        moving those that are included, but not excluded, into the *matched*
        set.

        Both *matched* and *unmatched* are sets of unqualified file names.
143
def match_files(self, matched, unmatched):
        """"""
        for pattern in self.iter():
            pattern.match_files(matched, unmatched)
            if not unmatched:
                # Optimization: If we have matched all files already
                # simply return at this point - nothing else to do
                break
600074
function execExclude(file) {
    var result = false;
    excludeList.every(function (item) {
      if (minimatch(file, item)) {
        result = true;
      }
      return !result;
    });
    return result;
  }
765293
def filter_models(request, models, exclude):
    
    items = get_avail_models(request)
    included = []

    def full_name(model):
        return '%s.%s' % (model.__module__, model.__name__)

    # I beleive that that implemented
    # O(len(patterns)*len(matched_patterns)*len(all_models))
    # algorythm is fine for model lists because they are small and admin
    # performance is not a bottleneck. If it is not the case then the code
    # should be optimized.

    if len(models) == 0:
        included = items
    else:
        for pattern in models:
            wildcard_models = []
            for item in items:
                model, perms = item
                model_str = full_name(model)
                if model_str == pattern:
                    # exact match
                    included.append(item)
                elif fnmatch(model_str, pattern) and \
                        item not in wildcard_models:
                    # wildcard match, put item in separate list so it can be
                    # sorted alphabetically later
                    wildcard_models.append(item)
            if wildcard_models:
                # sort wildcard matches alphabetically before adding them
                wildcard_models.sort(
                    key=lambda x: x[0]._meta.verbose_name_plural
                )
                included += wildcard_models

    result = included[:]
    for pattern in exclude:
        for item in included:
            model, perms = item
            if fnmatch(full_name(model), pattern):
                try:
                    result.remove(item)
                except ValueError:  # if the item was already removed skip
                    pass
    return result
503110
function filterFile(file, done) {
      if (files[file].partial) {
        // Discover whether it is explicitly declared as a partial.
        return done(null, files[file].partial)
      } else if (opts.pattern) {
        // Check if it matches the partial pattern.
        return done(null, minimatch(file, opts.pattern))
      }
      // The file is not a partial.
      done(null, false)
    }
328412
function filter(file) {
    if (files.indexOf(file) !== -1) return false;
    let include = true;
    regexs.forEach((regex) => {
      if (file.search(regex) !== -1) include = false;
    });
    return include;
  }
86430
function shouldBeIncluded(file) {

  if (!showAllFiles && file[0] === '.') {
    return false
  }
  if (hasExcludePattern) {
    return !excludePattern.test(file)
  }
  if (hasIncludePattern) {
    return includePattern.test(file)
  }
  return true
}
573252
public static boolean isExcluded(String filename, List<String> excludes) {
        logger.debug("filename = [{}], excludes = [{}]", filename, excludes);

        // No rules ? Fine, we index everything
        if (excludes == null || excludes.isEmpty()) {
            logger.trace("no rules");
            return false;
        }

        // Exclude rules : we know that whatever includes rules are, we should exclude matching files
        for (String exclude : excludes) {
            String regex = exclude.toLowerCase().replace("?", ".?").replace("*", ".*?");
            logger.trace("regex is [{}]", regex);
            if (filename.toLowerCase().matches(regex)) {
                logger.trace("does match exclude regex");
                return true;
            }
        }

        logger.trace("does not match any exclude pattern");
        return false;
    }
31202
function extensionMatches (filename) {
		var extname = path.extname(filename);
		if (extname) {
			return extname === extension;
		}
		return true;
	}
116890
def remove_excluded_files(files)
      return files if @exclude.empty?
      files.reject do |file|
        @exclude.any? { |exclude| File.fnmatch(exclude, file) }
      end
    end
15516
def filter_exclusions file_paths
      file_paths.reject do |path|
        exclude_file_patterns.any? { |pattern| File.fnmatch("#{pattern}", path) || File.fnmatch("**/#{pattern}", path) }
      end
    end
545554
private void checkIncludePatterns() {
        Map newroots = new HashMap();
        // put in the newroots map the include patterns without
        // wildcard tokens
        for (int i = 0; i < includes.length; i++) {
            if (FileUtil.isAbsolutePath(includes[i])) {
                //skip abs. paths not under basedir, if set:
                if (basedir != null
                    && !SelectorUtils.matchPatternStart(includes[i],
                    basedir.getAbsolutePath(), isCaseSensitive())) {
                    continue;
                }
            } else if (basedir == null) {
                //skip non-abs. paths if basedir == null:
                continue;
            }
            newroots.put(SelectorUtils.rtrimWildcardTokens(
                includes[i]), includes[i]);
        }
        if (newroots.containsKey("") && basedir != null) {
            // we are going to scan everything anyway
            scandir(basedir, "", true);
        } else {
            // only scan directories that can include matched files or
            // directories
            Iterator it = newroots.entrySet().iterator();

            File canonBase = null;
            if (basedir != null) {
                try {
                    canonBase = basedir.getCanonicalFile();
                } catch (IOException ex) {
                    throw new RuntimeException(ex);
                }
            }
            while (it.hasNext()) {
                Map.Entry entry = (Map.Entry) it.next();
                String currentelement = (String) entry.getKey();

                if (basedir == null && !FileUtil.isAbsolutePath(currentelement)) {
                    continue;
                }
                String originalpattern = (String) entry.getValue();
                File myfile = new File(basedir, currentelement);

                if (myfile.exists()) {
                    // may be on a case insensitive file system.  We want
                    // the results to show what's really on the disk, so
                    // we need to double check.
                    try {
                        String path = (basedir == null)
                            ? myfile.getCanonicalPath()
                            : FileUtil.removeLeadingPath(canonBase,
                            myfile.getCanonicalFile());
                        if (!path.equals(currentelement)) {
                            myfile = findFile(basedir, currentelement, true);
                            if (myfile != null && basedir != null) {
                                currentelement = FileUtil.removeLeadingPath(
                                    basedir, myfile);
                            }
                        }
                    } catch (IOException ex) {
                        throw new RuntimeException(ex);
                    }
                }
                if ((myfile == null || !myfile.exists()) && !isCaseSensitive()) {
                    File f = findFile(basedir, currentelement, false);
                    if (f != null && f.exists()) {
                        // adapt currentelement to the case we've
                        // actually found
                        currentelement = (basedir == null)
                            ? f.getAbsolutePath()
                            : FileUtil.removeLeadingPath(basedir, f);
                        myfile = f;
                    }
                }
                if (myfile != null && myfile.exists()) {
                    if (!followSymlinks
                        && isSymlink(basedir, currentelement)) {
                        continue;
                    }
                    if (myfile.isDirectory()) {
                        if (isIncluded(currentelement)
                            && currentelement.length() > 0) {
                            accountForIncludedDir(currentelement, myfile, true);
                        }  else {
                            if (currentelement.length() > 0) {
                                if (currentelement.charAt(currentelement
                                                          .length() - 1)
                                    != File.separatorChar) {
                                    currentelement =
                                        currentelement + File.separatorChar;
                                }
                            }
                            scandir(myfile, currentelement, true);
                        }
                    } else {
                        boolean included = isCaseSensitive()
                            ? originalpattern.equals(currentelement)
                            : originalpattern.equalsIgnoreCase(currentelement);
                        if (included) {
                            accountForIncludedFile(currentelement, myfile);
                        }
                    }
                }
            }
        }
    }
617556
private function doAddMatchers()
    {
        if (!empty($this->newMatchers)) {
            $this->shell->addMatchers($this->newMatchers);
            $this->newMatchers = [];
        }
    }
502420
def file_matches(filename, patterns):
    """"""
    return any(fnmatch.fnmatch(filename, pat)
               or fnmatch.fnmatch(os.path.basename(filename), pat)
               for pat in patterns)
634878
def _match_pattern(filename, include, exclude, real, path, follow):
    """"""

    if real:
        symlinks = {}
        if isinstance(filename, bytes):
            curdir = os.fsencode(os.curdir)
            mount = RE_BWIN_MOUNT if util.platform() == "windows" else RE_BMOUNT
        else:
            curdir = os.curdir
            mount = RE_WIN_MOUNT if util.platform() == "windows" else RE_MOUNT

        if not mount.match(filename):
            exists = os.path.lexists(os.path.join(curdir, filename))
        else:
            exists = os.path.lexists(filename)

        if not exists:
            return False
        if path:
            return _match_real(filename, include, exclude, follow, symlinks)

    matched = False
    for pattern in include:
        if pattern.fullmatch(filename):
            matched = True
            break

    if not include and exclude:
        matched = True

    if matched:
        matched = True
        if exclude:
            for pattern in exclude:
                if not pattern.fullmatch(filename):
                    matched = False
                    break
    return matched
151472
def match_local(self, prefix, includes, excludes):
        
        includes_pattern = r"|".join([fnmatch.translate(x) for x in includes])
        excludes_pattern = r"|".join([fnmatch.translate(x) for x in excludes]) or r"$."
        matches = []
        for root, dirs, files in os.walk(prefix, topdown=True):
            # exclude dirs
            dirs[:] = [os.path.join(root, d) for d in dirs]
            dirs[:] = [d for d in dirs if not re.match(excludes_pattern,
                                                       d.split(root)[1])]
            # exclude/include files
            files = [os.path.join(root, f) for f in files]
            files = [os.path.join(root, f) for f in files
                     if not re.match(excludes_pattern, f)]
            files = [os.path.join(root, f) for f in files
                     if re.match(includes_pattern, f.split(prefix)[1])]
            for fname in files:
                matches.append(fname)
        return matches
819508
def filter_files(files, path, path_without_extension, template_extensions)
      results = []

      files.each do |file|
        match = if file.start_with?(path)
                  path
                else
                  path_without_extension
                end

        processable_extensions = file[(match.length + 1)..-1].split(".")

        # All processable_extensions must be processable
        # by a template_extension
        next unless (processable_extensions - template_extensions).empty?

        if file.start_with?(path)
          # The whole path is found in the filename, not just
          # the path without the extension.
          # it must have priority over all else
          results.unshift(file)
        else
          results.push(file)
        end
      end
      results
    end
970411
function filterIgnored(files, ignore, fn) {
  fn(null, files.filter(function(file) {
    // TODO make more robust
    return !~ignore.indexOf(file) && !~ignore.indexOf(file + '/');
  }));
}