Get images list of a folder

Hi! Another question.
I need to obtain the list of images of a folder and put them in an array, so that the script could choose one of them. I can’t find methods to access folders content. Any suggestion?
I’m looking also for generic methods to work with floders, subfolder, file in the folders and so on. Thanks.

Define a list of image file extensions and use e.g. the following method:

Ok, thankyou, I did it. This is the solution for my case.

import bpy, random, os, fnmatch, ntpath

exts = ["*.png", "*.tif", "*.tiff"]

#getting graphics list
for root, dirnames, filenames in os.walk(graphics_path): #put here the folder where you want search
         for ext in exts: #do the search for each extension in the list
                   for filename in fnmatch.filter(filenames, ext): #here specify the  wanted file extension. Do a loop for each want you want find
                          graphics_list.append(os.path.join(root, filename))  #here add the file found to the list

#it returns a list of complete path of the files found
#if you want just the name of the file, use this function, that should work even under win and linux

def get_filename(path):
         head, tail = ntpath.split(path)
         return tail or ntpath.basename(head)

bye and thankyou again!

If there are a lot of files, and you know you won’t read all their names, you should turn the matcher into a generator.