title: Iterate through folder with Pillow Image.open
body: <p>I am trying to iterate through a folder of .png files and OCR them. The iteration works but as soon as I try to open Images with PIL it gives errors.</p>
  
  <pre><code>import pytesseract
  from PIL import Image
  import os
  
  for filename in os.listdir('C:/Users/Artur/Desktop/Sequenz_1'):
      if filename.endswith('.png'):
          print(filename)
  </code></pre>
  
  <p>This works just fine. It prints every .png filename in the folder. But when I try to OCR:</p>
  
  <pre><code>import pytesseract
  from PIL import Image
  import os
  
  for filename in os.listdir('C:/Users/Artur/Desktop/Sequenz_1'):
      if filename.endswith('.png'):
          print(pytesseract.image_to_string(Image.open(filename)))
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:\Users\Artur\Desktop\Pytesseract_test.py", line 8, in &lt;module&gt;
      print(pytesseract.image_to_string(Image.open(filename)))
    File "C:\Users\Artur\AppData\Local\Programs\Python\Python36\lib\site-packages\PIL\Image.py", line 2580, in open
      fp = builtins.open(filename, "rb")
  FileNotFoundError: [Errno 2] No such file or directory: 'frame_0000.png'
  </code></pre>
  
  <p>Edit:</p>
  
  <p>Thanks to Benehiko it works fine now. </p>
  
  <p>Code:</p>
  
  <pre><code>import pytesseract
  from PIL import Image
  import glob
  
  
  images = glob.glob('C:/Users/Artur/Desktop/Sequenz_1/*.png')
  
  for image in images:
      with open(image, 'rb') as file:
          img = Image.open(file)
          print(pytesseract.image_to_string(img))
  </code></pre>