Home > Back-end >  How to print length of images folder
How to print length of images folder

Time:10-15

I have a folder having 7000 images. I want to find the exact length of these images.

path = "/content/drive/MyDrive/iuxray/images/images_normalized"

I use the following code for printing the length of total number of images in this folder.

print(f"Number of images: {len(path)}")

But it prints just 54 images like below

Number of images: 54

So I want to know where am I doing wrong? How to print the exact number of images

CodePudding user response:

You were printing the length of the directory path which is a string, this should give the list of files and its length

import os
path = "/content/drive/MyDrive/iuxray/images/images_normalized"
fileList=os.listdir(path)
print(len(fileList))
  • Related