def find_files(directory, pattern, recursively=True):
for root, dirs, files in os.walk(directory):<EOL><INDENT>for basename in files:<EOL><INDENT>if fnmatch.fnmatch(basename, pattern):<EOL><INDENT>yield root, basename<EOL><DEDENT><DEDENT>if not recursively:<EOL><INDENT>break<EOL><DEDENT><DEDENT>
Yield a list of files with their base directories, recursively or not.

Returns:
    A list of (base_directory, filename)

Args:
    directory: base directory to start the search.
    pattern: fnmatch pattern for filenames.
    complete_filename: return complete filename or not?
    recursively: do we recurse or not?