How to get number of images folder

Question:

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

Asked By: Tensor

||

Answers:

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))
# for checking whether file is not a directory
print(len([fname for fname in os.listdir(path) if os.path.isfile(os.path.join(path, fname))]))
Answered By: Kaneki21
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.