title: How to open a random Image from a given file directory?
body: <p>I am trying to open the image from this directory but am not been able to.
  It gives me the following error:</p>
  
  <blockquote>
    <p>WindowsError: [Error 123] The filename, directory name, or volume
    label syntax is incorrect.  </p>
  </blockquote>
  
  <p>This is my code: </p>
  
  <pre><code>import os, random
  random.choice(os.listdir("C:\\Users\rkp10\AppData\Local\Google\Chrome\User Data\Default\Extensions\laookkfknpbbblfpciffpaejjkokdgca\0.91.6_0\backgrounds"+'png'))
  </code></pre>
  
  <p>In here , in the folder backgrounds there are many images.I want a random Image to open.But while running the program , I am getting <code>WindowsError</code>.</p>
  
  <p>What am I doing wrong?</p>
  
  <h1>Edit 1</h1>
  
  <p>I tried this:</p>
  
  <pre><code>random.choice(os.listdir(r"C:\Users\rkp10\AppData\Local\Google\Chrome\User Data\Default\Extensions\laookkfknpbbblfpciffpaejjkokdgca\0.91.6_0\backgrounds"+'png'))
  </code></pre>
  
  <p>But am getting the error:</p>
  
  <blockquote>
    <p>WindowsError: [Error 123] The filename, directory name, or volume
    label syntax is incorrect:
    'C:\Users\rkp10\AppData\Local\Google\Chrome\User
    Data\Default\Extensions\laookkfknpbbblfpciffpaejjkokdgca\0.91.6_0\backgrounds\*.png/<em>.</em>'</p>
  </blockquote>
  
  <h1>Edit 2</h1>
  
  <p>I tried this:</p>
  
  <pre><code>import os, random
  
  a=random.choice(os.listdir(r"C:\Users\rkp10\AppData\Local\Google\Chrome\User Data\Default\Extensions\laookkfknpbbblfpciffpaejjkokdgca\0.91.6_0\backgrounds"))
  os.open(a)
  </code></pre>
  
  <p>Now I dont get error but it does not open the image either. </p>
  
  <h1>Edit 3</h1>
  
  <p>I have also tried:</p>
  
  <pre><code> import random,os
  folder= "C:\\Users\rkp10\AppData\Local\Google\Chrome\User Data\Default\Extensions\laookkfknpbbblfpciffpaejjkokdgca\0.91.6_0\backgrounds"
  a=random.choice(os.listdir(folder))
  print(a)
  
  from PIL import Image
  file = folder+'\\'+a
  Image.open(file).show()
  
      #os.open(a, os.O_RDWR)
      from PIL import Image
      file = folder+'\\'+a
      Image.open(file).show()
  </code></pre>
  
  <p>But got the following error once again:</p>
  
  <blockquote>
    <p>Traceback (most recent call last):   File "G:\Grade 12
    Project\auto.py", line 4, in 
        a=random.choice(os.listdir(folder)) WindowsError: [Error 123] The filename, directory name, or volume label syntax is incorrect:
    'C:\Users\rkp10\AppData\Local\Google\Chrome\User
    Data\Default\Extensions\laookkfknpbbblfpciffpaejjkokdgca'</p>
  </blockquote>
  
  <p>Here(the yellow highlighted part) is the directory where my images are stored.</p>
  
  <p><a href="https://i.stack.imgur.com/T0NAZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/T0NAZ.png" alt="Image of Directory"></a></p>