do a recursive scan of the top level target file
        This lets us search for included files based on the
        directory of the main file just as latex does
356728
def scan_recurse(self, node, path=()):
        

        path_dict = dict(list(path))
        
        queue = [] 
        queue.extend( self.scan(node) )
        seen = {}

        # This is a hand-coded DSU (decorate-sort-undecorate, or
        # Schwartzian transform) pattern.  The sort key is the raw name
        # of the file as specifed on the \include, \input, etc. line.
        # TODO: what about the comment in the original Classic scanner:
        # """which lets
        # us keep the sort order constant regardless of whether the file
        # is actually found in a Repository or locally."""
        nodes = []
        source_dir = node.get_dir()
        #for include in includes:
        while queue:
            
            include = queue.pop()
            inc_type, inc_subdir, inc_filename = include

            try:
                if seen[inc_filename] == 1:
                    continue
            except KeyError:
                seen[inc_filename] = 1

            #
            # Handle multiple filenames in include[1]
            #
            n, i = self.find_include(include, source_dir, path_dict)
            if n is None:
                # Do not bother with 'usepackage' warnings, as they most
                # likely refer to system-level files
                if inc_type != 'usepackage':
                    SCons.Warnings.warn(SCons.Warnings.DependencyWarning,
                                        "No dependency generated for file: %s (included from: %s) -- file not found" % (i, node))
            else:
                sortkey = self.sort_key(n)
                nodes.append((sortkey, n))
                # recurse down
                queue.extend( self.scan(n, inc_subdir) )

        return [pair[1] for pair in sorted(nodes)]
816005
private Collection<File> doListAllFiles(File rootDir,
                                            boolean includeDirectories) {
        Collection<File> result = new Stack<File>();
        File[] files = rootDir.listFiles();
        for (File f : files) {
            if (f.isDirectory()) {
                if (includeDirectories) {
                    result.add(f);
                }
                result.addAll(doListAllFiles(f, includeDirectories));
            } else if (f.isFile()) {
                result.add(f);
            }
        }
        return result;
    }
477043
def iter_tex_documents(base_dir="."):
    """"""
    for path, dirlist, filelist in os.walk(base_dir):
        for name in fnmatch.filter(filelist, "*.tex"):
            yield os.path.join(path, name)
484854
def get_file_list(self, lstPaths, lstXtn, lstExcluded, VERBOSE = False):
        
        if VERBOSE:
            print("Generating list of Files...")
            print("Paths = ", lstPaths)
            print("Xtns  = ", lstXtn)
            print("exclude = ", lstExcluded)
        numFiles = 0
        self.filelist = []
        self.fl_metadata = []
        for rootPath in lstPaths:
            if VERBOSE:
                print(rootPath)
            for root, dirs, files in os.walk(rootPath):
                if VERBOSE:
                    print(dirs)
                for basename in files:
                    for xtn in lstXtn:
                        if fnmatch.fnmatch(basename, xtn):
                            filename = os.path.join(root, basename)
                            includeThisFile = "Y"
                            if len(lstExcluded) > 0:
                                for exclude in lstExcluded:
                                    if filename.find(exclude) != -1:
                                        includeThisFile = "N"
                            if includeThisFile == "Y":
                                numFiles = numFiles + 1
                                self.filelist.append(filename)
                                self.add_file_metadata(filename)    # not sure why there is a 2nd list, but there is.

        if VERBOSE:
            print("Found ", numFiles, " files")
        return self.filelist
835946
def matching_files(self):
        
        matching = []
        matcher = self.file_path_regex
        pieces = self.file_path_regex.pattern.split(sep)
        partial_matchers = list(map(re.compile, (
            sep.join(pieces[:i + 1]) for i in range(len(pieces)))))

        for root, dirs, files in walk(self.top_dir, topdown=True):
            for i in reversed(range(len(dirs))):
                dirname = relpath(join(root, dirs[i]), self.top_dir)
                dirlevel = dirname.count(sep)
                if not partial_matchers[dirlevel].match(dirname):
                    del dirs[i]

            for filename in files:
                if matcher.match(filename):
                    matching.append(abspath(join(root, filename)))

        return matching
35582
def find_files(root, pattern):
    
    results = []
    for base, dirs, files in os.walk(root):
        matched = fnmatch.filter(files, pattern)
        results.extend(os.path.join(base, f) for f in matched)
    return results
1365115
def _check_scan_dir(self, fs, path, info, depth):
        # type: (FS, Text, Info, int) -> bool
        """"""
        if self.max_depth is not None and depth >= self.max_depth:
            return False
        return self.check_scan_dir(fs, path, info)
1027199
function findMainFiles(name, component, meta) {
			grunt.verbose.writeln();
			grunt.verbose.writeln('Finding main file for ' + name + '...');
			var mainFiles = ensureArray(component);

			// Main file explicitly defined in bower_concat options
			if (mains[name]) {
				var componentDir = meta && meta.canonicalDir || path.join(bowerDir, bower.config.directory, name);
				var manualMainFiles = ensureArray(mains[name]);
				manualMainFiles = _.map(manualMainFiles, joinPathWith(componentDir));
				grunt.verbose.writeln('Main file was specified in bower_concat options: ' + manualMainFiles);
				return manualMainFiles;
			}

			// Bower knows main JS file?
			mainFiles = _.map(mainFiles, joinPathWith(bowerDir));
			var mainJSFiles = _.filter(mainFiles, function(file) { return isFileExtension(file, '.js'); });
			var mainCSSFiles = _.filter(mainFiles, function(file) { return isFileExtension(file, '.css'); });
			var mainSCSSFiles = _.filter(mainFiles, function(file) { return isFileExtension(file, '.scss'); });
			var allMainFiles = mainJSFiles.concat(mainCSSFiles.concat(mainSCSSFiles));

			if (allMainFiles.length) {
				grunt.verbose.writeln('Main file was specified in bower.json: ' + allMainFiles);
				return allMainFiles;
			}

			// Try to find main JS, CSS, SCSS files
			var jsFiles = expandForAll(component, joinPathWith(bowerDir, '*.js'));
			var cssFiles = expandForAll(component, joinPathWith(bowerDir, '*.css'));
			var scssFiles = expandForAll(component, joinPathWith(bowerDir, '*.scss'));

			// Skip Gruntfiles
			jsFiles = _.filter(jsFiles, function(filepath) {
				return !/(Gruntfile\.js)|(grunt\.js)$/.test(filepath);
			});

			var mainJsFiles = [];
			if (jsFiles.length === 1) {
				// Only one JS file: no doubt it’s main file
				grunt.verbose.writeln('Considering the only JS file in a component’s folder ' +
					 'as a main file: ' + jsFiles
						);
				mainJsFiles = jsFiles;
			}
			else {
				// More than one JS file: try to guess
				var bestFile = guessBestFile(name, jsFiles);
				if (bestFile) {
					grunt.verbose.writeln('Guessing the best JS file in a component’s folder: ' + [bestFile]);
					mainJsFiles = [bestFile];
				}
				else {
					grunt.verbose.writeln('Main JS file not found');
				}
			}
			return mainJsFiles.concat(cssFiles);
		}
704197
def recursive_include(self, dir, pattern):
        
        full_pattern = os.path.join(dir, '**', pattern)
        found = [f for f in glob(full_pattern, recursive=True)
                 if not os.path.isdir(f)]
        self.extend(found)
        return bool(found)
9174
def find_include_file(name)
      to_search = [ File.dirname(@input_file_name) ].concat @include_path
      to_search.each do |dir|
        full_name = File.join(dir, name)
        stat = File.stat(full_name) rescue next
        return full_name if stat.readable?
      end
      nil
    end
1233942
def _get_files_recursively(rootdir):
    
    output = []
    for root, dirs, files in os.walk(rootdir):
        for filename in files:
            output.append(os.path.join(root, filename))

    return output
1165384
def recursive_search glob="**/*"
      @command = Proc.new {|str| Dir.glob(glob).select do |p| p.index str; end }
    end
889268
function expandIncludes(source, rootPath) {
	var matcher = new RegExp("^([\t ]*)include ([^/].*);\n?", "gm");
	var match;
	var expanded = '';
	var after = source;
	var includes = [];
	var lastIndex = 0;
	while (match = matcher.exec(source)) {
		var statement = match[0];
		var indent = match[1];
		var filePath = path.join(rootPath, match[2])
		includes.push(filePath);

		expanded += source.substr(lastIndex, match.index - lastIndex);

		expanded += indent + "## Start Include: " + filePath + "\n";

		try {
			var fileContent = fs.readFileSync(filePath, 'utf8');

			// preserve indentation of the include line
			var indentedContent = singleTrailingNewline(NgindoxUtil.indentBlock(fileContent, indent));

			// recurse with relative path
			expanded += expandIncludes(indentedContent, path.dirname(rootPath));
		} catch (err) {
			// file probably missing
			expanded += indent + "## Error: " + err + "\n";
		}

		expanded += indent + "## End Include: " + filePath + "\n";

		// store end of match as begining of next search
		lastIndex = matcher.lastIndex;
	}

	expanded += source.substr(lastIndex);

	return expanded;
}
1196866
def find_top_level_directory(start_directory):
    
    top_level = start_directory
    while os.path.isfile(os.path.join(top_level, '__init__.py')):
        top_level = os.path.dirname(top_level)
        if top_level == os.path.dirname(top_level):
            raise ValueError("Can't find top level directory")
    return os.path.abspath(top_level)
329168
def _fetchFilesFromFolder(self, target, recursive):
        '''
            
        '''
        directory_items = os.walk(target)

        # If recursive is false, fetch only the first tuple
        if not recursive:
            directory_items = [next(directory_items)]

        targets = []
        for dir_name, folders, files in directory_items:
            for f in files:
                targets.append(os.path.join(dir_name, f))

        return targets
1290225
def scan_dir(self, path):
        

        """
        for fname in glob.glob(os.path.join(path, '*' + TABLE_EXT)):
            if os.path.isfile(fname):
                with open(fname, 'r') as fobj:
                    try:
                        self.add_colortable(fobj, os.path.splitext(os.path.basename(fname))[0])
                        log.debug('Added colortable from file: %s', fname)
                    except RuntimeError:
                        # If we get a file we can't handle, assume we weren't meant to.
                        log.info('Skipping unparsable file: %s', fname)
1118912
function filter_and_recursion_processing(file) {
    const filePath = path.join(...basePath, ...directoryPath, file);

    if (path.extname(file) === extension) {
      // partial file is found, passing through filter, process it later
      return file;
    } else if (fs.statSync(filePath).isDirectory()) {
      // directory found, do recursion and get processed partials back
      partials = partials.concat(
        getPartials({
          basePath,
          directoryPath: [...directoryPath, file],
          extension,
          encoding,
          getNameFunc
        })
      );
    }

    return false;
  }