0

I have a folder with subfolders. Every subfolder contains 20 images. I want to process the images and save them and processing them to another path.

this is my code:

How to do that? to go through very subfolder and every image from the subfolder, processed them and then save them?

Faza C
  • 13
  • 2
  • The os.walk() function helps you go recursively through every subfolder. Here's a post that gives an example: https://stackoverflow.com/questions/3207219/how-do-i-list-all-files-of-a-directory/3207973#3207973 – ma3oun May 30 '17 at 07:10

1 Answers1

0

Use the following code to iterate over your folder and subfolders:

for subdir, dirs, files in os.walk(path):   # walks through whole directory
    for file in files:
        filepath = os.path.join(subdir, file)  # path to the file
        #your code here  

Then, distinguish images by checking if the path has the correct extension:

if '.jpg' in filepath or '.png' in filepath:
    #do something
Isdj
  • 1,835
  • 1
  • 18
  • 36