Krupali Mistry
Krupali Mistry

Reputation: 644

In python, to consider the image files based on their names for computing

i have 60000+ images in one folder and i want to include files based on their names in computing values. I am giving the parameter as "year" and my image file names are like

year = '2015'
170519-1-27-1 represents 2017
161022-1-31-1 represents 2016
150926-1-27-1 represents 2015
140821-1-65-1 represents 2014
121011-4-39-1 represents 2012
090714-2-36-1 represents 2009

For example if the year is "2015" I want to include files uptill 2014 and exclude (only exclude not to delete/remove) 2015 , 2016 and 2017 files for computing some values.

How do I do that ? Here the code which i tried:

year = '2015'
for oimg in sorted(glob.glob(inputdir + '*.jpg')):
            
            img_path = oimg.split('/')[-1]
            imgstr = img_path.split('.')[0]
            
            if imgstr[:2] < year[2:4]:
               continue
            print(imgstr)

Upvotes: 1

Views: 31

Answers (1)

Varsha Kishore
Varsha Kishore

Reputation: 181

Extract the last 4 characters of the filename, cast it to a int and check if it is less than or equal to int(year).

Upvotes: 1

Related Questions