# Best way to load image from list python script

For some reason i have append images , now i want load all image by step.

image_path  = C:
image_list= []
for fn in os.listdir(image_path):
image_list.append(fn)


Try this to batch load a list of images in a folder:

import bpy
from os.path import join, isfile
from os import listdir

imageObjects = []
imagePath = '/users/you/yourImagePath'
imgFiles  = [
join( imagePath, fn )                    # Create full paths to images
for fn in listdir( imagePath )           # For each item in the image folder
if isfile( join( imagePath, fn ) )       # If the item is indeed a file
and fn.lower().endswith(('.png','.jpg')) # Which ends with an image suffix (can add more types here if needed)
]

# Load entire list of images
for imgFile in imgFiles:
# Add to image object list to use later

# Load a specific index from the list (5th in the list in this example)

• ty but i have to load not full image list because have some variable by controlling the loading , i have to know the way by load single image from list. for example the first image of the list and in the second step , load second image. Apr 2, 2019 at 8:48
• @Andrea see edit and LMK if this is what you meant Apr 2, 2019 at 8:57
• Sorry @TLousky in the first time i put name of node with diffuse = nodes.new(type='ShaderNodeTexImage') diffuse.location = (-600,550) diffuse.name = imgFiles[0] now name is all path of image.. in the first time is only image name. an idea? Apr 2, 2019 at 9:25
• try to replace the imports from os.path and add basename. Like this: from os.path import join, isfile, basename. Then use it in the diffuse.name: diffuse.name = basename(imgFiles[0]). Basename extracts the filename from a full path. Apr 2, 2019 at 9:34
• Work very fine is very usefull, ty Apr 2, 2019 at 9:41