path to all images in folder python code example
Example 1: python get all images in directory
import glob
for filename in glob.iglob(root_dir + '**/*.jpg', recursive=True):
Example 2: how to print all images path python
""
code to print all jpg, png, docx, pdf. for the path provided
""
def process(contentpath):
jpg_images = glob.glob(contentpath + '/*.jpg')
print("jpg images \n",jpg_images)
png_images = glob.glob(contentpath + '/*.png')
print("\n png images \n",png_images)
documents = glob.glob(contentpath + '/*.docx')
print("\n docxx - \n",documents)
pdfs_inside = glob.glob(contentpath + '/*.pdf')
print("\n pdfsss - \n ",pdfs_inside)
return
process(r' input the path of the folder here ')
Example 3: import all images from folder python
from PIL import Image
import glob
image_list = []
for filename in glob.glob('yourpath/*.gif'):
im=Image.open(filename)
image_list.append(im)