Read All images from directory in Python and try to store it in array [closed]

Read Directory

files= os.listdir(Datadir)
print(files)

This my all classes

Classes = ['happy', 'surprise', 'fear', 'angry', 'neutral', 'sad', 'disgust']

I want to read all data and store it in array Training_data = []

def create_training_Data():
for category in Classes:
    class_num = Classes.index(category)
    labels = class_num
    
    
    total=Datadir+'/'+category
    Files= os.listdir(total)
    
for img in Files:
    file_main=total+'/'+img
    print(file_main+"   "+str(label))
    img_array = cv2.imread(file_main)
    new_array = cv2.resize(img_array, (img_size,img_size))
    Training_data.append([new_array,class_num])

Those line of code only can read “disgust” this classes data enter image description here

Where is the mistake please help me , any suggestion give me. Thanks in advance

Answer

 Training_data = []

def create_training_Data():
for category in files:
    class_num = Classes.index(category)
    label = class_num        
    
    total=Datadir+'/'+category
    Files= os.listdir(total)
    
    for img in Files:           
        try:
            file_main=total+'/'+img
            print(file_main+"   "+str(label))
            old_image= cv2.imread(file_main)
            new_image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
            new_image= cv2.resize(image,(48,48))
            Training_data.append([new_image,label])
        except Exception as e:
            pass

Those line of code is working for me. Those lines of code will work with exception/error handling.