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
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))]))
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
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))]))