def _populate(self, pattern, recursive = False, file_only = False):
        """
            The main workhorse function for adding files to the list.
            Returns the pattern, if it's just a filesystem item and
            it exists in the filesystem. Returns a list if pattern contains
            wildcards, or None, if the wildcards do not match anything.
        """
        temp = []
        wildcard = False

        # look for wildcard characters in the pattern
        if ('*' in pattern) or ('?' in pattern)\
         or ('[' in pattern):
            wildcard = True
        # items added to the list must exist on the filesystem.
        if not wildcard and not os.path.exists(pattern):
            raise ValueError, ("Item not found on file system: %s"% pattern)

        # if it's a directory, assume they want every file there.
        if os.path.isdir(pattern):
            pattern = os.path.join(pattern, '*')
            wildcard = True
        # expand any wildcards
        if wildcard:
            temp.extend(glob.glob(pattern))

        # walk through any directories, if requested,
        # using the same pattern, if any.
        if recursive:
            path, filter = os.path.split(pattern)

            # Go through the path, finding all the directories
            if wildcard:
                # try os.walk first, which is in python2.3
                try:
                    for root, dirs, files in os.walk(path):
                        for dir in dirs:
                            temp.extend(glob.glob(\
                                os.path.join(root, dir, filter)))
                except AttributeError:
                    # probably running on something less than python2.3
                    dirlist = self._walktree_compat(path)
                    for dir in dirlist:
                        temp.extend(glob.glob(os.path.join(dir, filter)))

        # Finally, kill any links that got through from glob
        # and remove anything that's not a file, if requested.
        temp2 = []
        name = ''
        while True:
            try:
                # use pop() on the theory that it saves memory
                # (one list is reduced while the other grows).
                # That's probably not true, but I wouldn't know.
                name = temp.pop()
                try:
                    mode = os.stat(name)[ST_MODE]
                except OSError, err:
                    import errno
                    if err.errno != errno.ENOENT: raise
                    # file not found. Most likely a broken symlink
                    continue
                if file_only and S_ISREG(mode) and not S_ISLNK(mode):
                    temp2.append(name)
                elif not S_ISLNK(mode):
                    temp2.append(name)
            except IndexError:
                break
        temp = temp2
            
        # Return the list found
        if len(temp) > 0:
            return temp
        elif len(temp) == 0 and wildcard:
            # the wildcard search didn't find anything
            return None
        else:
            return pattern

            The main workhorse function for adding files to the list.
            Returns the pattern, if it's just a filesystem item and
            it exists in the filesystem. Returns a list if pattern contains
            wildcards, or None, if the wildcards do not match anything.
        
recipes/Python/259147_FSList/recipe-259147.py