code: def find_fragments(base_directory, sections, fragment_directory, definitions):
      
      content = OrderedDict()
      fragment_filenames = []
  
      for key, val in sections.items():
  
          if fragment_directory is not None:
              section_dir = os.path.join(base_directory, val, fragment_directory)
          else:
              section_dir = os.path.join(base_directory, val)
  
          files = os.listdir(section_dir)
  
          file_content = {}
  
          for basename in files:
              parts = basename.split(u".")
  
              counter = 0
              if len(parts) == 1:
                  continue
              else:
                  ticket, category = parts[:2]
  
              # If there is a number after the category then use it as a counter,
              # otherwise ignore it.
              # This means 1.feature.1 and 1.feature do not conflict but
              # 1.feature.rst and 1.feature do.
              if len(parts) > 2:
                  try:
                      counter = int(parts[2])
                  except ValueError:
                      pass
  
              if category not in definitions:
                  continue
  
              full_filename = os.path.join(section_dir, basename)
              fragment_filenames.append(full_filename)
              with open(full_filename, "rb") as f:
                  data = f.read().decode("utf8", "replace")
  
              if (ticket, category, counter) in file_content:
                  raise ValueError(
                      "multiple files for {}.{} in {}".format(
                          ticket, category, section_dir
                      )
                  )
              file_content[ticket, category, counter] = data
  
          content[key] = file_content
  
      return content, fragment_filenames
docs: Sections are a dictonary of section names to paths.