title: Extract metadata from multiple images and store it in a list
body: <p>I am trying to extract certain bits of metadata from .jpg images in a directory.
  I am able to extract it form one image at a time with the following code:</p>
  
  <pre><code>    from PIL import Image, ExifTags
  img = Image.open("C:../Inpex_Mangrove_test/Original_Photos/DSC_0056.JPG.JPG")
  exif = { ExifTags.TAGS[k]: v for k, v in img._getexif().items() if k in ExifTags.TAGS }
  md_list= [exif['Model'], exif['DateTimeDigitized']]#creates a list from the fields required
  md_list
  </code></pre>
  
  <p>But I can not seem to be able to loop through and extract the code from all the images and store it in a list using this code:</p>
  
  <pre><code>   from PIL import Image, ExifTags
  import glob
  
  metadata =[]
  
  def extract_metadata(filename):
      # extract metadata
      image = Image.open(filename)
      exif = { ExifTags.TAGS[k]: v for k, v in image._getexif().items() if k in ExifTags.TAGS }
      model = exif['Model']
      datetime =exif['DateTimeDigitized']#creates a list from the fields required          
  
      return model + '_' + datetime
  
  # Loop through all jpeg files and create a list for metadatda extraction for each
  for image_file in glob.glob("path/*.jpg"):
      md_file = extract_metadata(image_file)
  
      metadata.append((f"{image_file} {md_file}"))#convert output into a list
  
  metadata
  </code></pre>
  
  <p>Thank you in advice for your help it is much appreciated.</p>