Python's method for selecting more than 300 images in a folder

  • 2020-04-02 14:38:25
  • OfStack

This example shows you how to pick a folder larger than 300 images in Python. Share with you for your reference. Specific analysis is as follows:

This code needs to use the PIL library. The code is as follows:


import sys
import os
sys.path.append('PIL')
from PIL import Image as im
path = '/home/hualun/ desktop /img/'
new_path = '/home/hualun/ desktop /img2/'
for x in os.listdir(path):
  if x.endswith('.jpg'):
    file = im.open(path+x)
    width = file.size[0]
    if width > 300:
      os.rename(path+x, new_path+x)
      print "%s  Move to complete .." % x

I hope this article has helped you with your Python programming.


Related articles: