title: raise RuntimeError(f"Directory '{directory}' does not exist") RuntimeError: Directory 'static/' does not exist from import fitz
body: <p>I am getting this error when I run extract_img.py file:</p>
  <blockquote>
  <p>RuntimeError(f“Directory '{directory}' does not exist”)<br />
  RuntimeError: Directory 'static/' does not exist from import fitz</p>
  </blockquote>
  <p>I don't understand why this sends me back this error message.
  I saw the conversation dealing with this topic before but I did not understand the solution. Could you help me?</p>
  <p>This file is intended to extract certain images from a PDF filesome images in a file.</p>
  <pre><code>from os import chdir
  import shutil, os
  import io
  from PIL import Image
  import fitz
  from unif_noun import unif_noun #other file python for change file noun.
  
  def execute_func(rootdir):
  for subdir, dirs, files in os.walk(rootdir):
      for file in files:
          filepath = subdir + os.sep + file
          if filepath.endswith(&quot;.pdf&quot;):
              #extract(f&quot;{filepath}&quot;)
              # open the file
              pdf_file = fitz.open(file)
              images = list()
              for page_index in range(len(pdf_file)):
                  # get the page itself
                  page = pdf_file[page_index]
                  image_list = page.getImageList()
                  # printing number of images found in this page
                  # if image_list:
                  #     print(f&quot;[+] Found a total of {len(image_list)} images in page {page_index}&quot;)
                  # else:
                  #     print(&quot;[!] No images found on page&quot;, page_index)
                  for image_index, img in enumerate(page.getImageList(), start=1):
                      images.append(img[0])
              for i, xref in enumerate(images, start=1):
                  if 1 &lt; i &lt; len(images) - 3:
                      # extract the image bytes
                      base_image = pdf_file.extractImage(xref)
                      image_bytes = base_image[&quot;image&quot;]
                      # get the image extension
                      image_ext = base_image[&quot;ext&quot;]
                      # load it to PIL
                      image = Image.open(io.BytesIO(image_bytes))
                      # save it to local disk
                      image.save(open(f&quot;{unif_noun(file)}.{image_ext}&quot;, &quot;wb&quot;))
                      # Déplacer un fichier du répertoire
                      for subdir, dirs, files in os.walk(rootdir):
                          for f in files:
                              source = subdir
                              destination = 'C:/Users/.../VS Projects/img'
                              filename = os.path.basename(source)
                              dest = os.path.join(destination,filename)
                              shutil.move(source + f&quot;{unif_noun(file)}.{image_ext}&quot;, dest)
  execute_func(r'C:/Users/Factoryz Amandine/OneDrive/Bureau/Python/CCOR02752150_3.pdf')[enter image description here][1]
  </code></pre>