def list_files(d, extension=None):
if os.path.isdir(d):<EOL><INDENT>expanded_dir = os.path.expanduser(d)<EOL>files = sorted(glob.glob(expanded_dir + '<STR_LIT>'))<EOL><DEDENT>else:<EOL><INDENT>files = [d, ]<EOL><DEDENT>if extension is not None:<EOL><INDENT>if type(extension) in STR_TYPES:<EOL><INDENT>extension = [extension, ]<EOL><DEDENT>files = [f for f in files if any([f.split('<STR_LIT:.>')[-<NUM_LIT:1>] in extension,<EOL>f.split('<STR_LIT:.>')[-<NUM_LIT:1>].upper() in extension,<EOL>f.split('<STR_LIT:.>')[-<NUM_LIT:1>].lower() in extension])]<EOL><DEDENT>return files<EOL>
Lists files in a given directory.

Args:

    d (str): Path to a directory.

    extension (str): If supplied, only files that contain the
        specificied extension will be returned. Default is ``False``,
        which returns all files in ``d``.

Returns:

    list: A sorted list of file paths.