title: How to create and add files to a directory?
body: <p>I'm writing a program to take large PDF's and convert each page to a .jpg, then add the .jpg's of each pdf file to their own directory (which the program needs to create).</p>
  <p>I have completed the conversion part of the program, but I am stuck on creating a directory and adding the files to the directory.</p>
  <p>Here's my code so far.</p>
  <pre><code>import glob, sys, fitz, os, shutil
  
  zoom_x = 2.0
  zoom_y = 2.0
  mat = fitz.Matrix(zoom_x, zoom_y)  # to get better resolution
  all_files = glob.glob('/Users/homefolder/Downloads/*.pdf')  # image path
  print(all_files)
  
  for filename in all_files:
      doc = fitz.open(filename)
      head, tail = os.path.split(doc.name)
      save_file_name = tail.split('.')[0]
      for page in doc:  # iterate through the pages
          # print(page)
          pix = page.get_pixmap(matrix=mat)
          # render the image
          filepath_save = '/Users/homefolder/Downloads/files' + save_file_name + str(page.number) + '.jpg'
          pix.save(filepath_save)  # save image
          
  sample = glob.glob('/Users/homefolder/Downloads/*.jpg')
  </code></pre>
  <p>How would I write the code to create a directory for each pdf file and add those .jpg's to the directory?</p>