def _ExpandDirectories(filenames):
expanded = set()<EOL>for filename in filenames:<EOL><INDENT>if not os.path.isdir(filename):<EOL><INDENT>expanded.add(filename)<EOL>continue<EOL><DEDENT>for root, _, files in os.walk(filename):<EOL><INDENT>for loopfile in files:<EOL><INDENT>fullname = os.path.join(root, loopfile)<EOL>if fullname.startswith('<STR_LIT:.>' + os.path.sep):<EOL><INDENT>fullname = fullname[len('<STR_LIT:.>' + os.path.sep):]<EOL><DEDENT>expanded.add(fullname)<EOL><DEDENT><DEDENT><DEDENT>filtered = []<EOL>for filename in expanded:<EOL><INDENT>if os.path.splitext(filename)[<NUM_LIT:1>][<NUM_LIT:1>:] in GetAllExtensions():<EOL><INDENT>filtered.append(filename)<EOL><DEDENT><DEDENT>return filtered<EOL>
Searches a list of filenames and replaces directories in the list with
    all files descending from those directories. Files with extensions not in
    the valid extensions list are excluded.

    Args:
      filenames: A list of files or directories

    Returns:
      A list of all files that are members of filenames or descended from a
      directory in filenames