In [12]:
import os, shutil
rootdir = 'D:/images'
lvldirs = {'high': 'D:/images_split/high_images',
'medium': 'D:/images_split/medium_images',
'low': 'D:/images_split/low_images'}
listing_photos = {}
with open('C:/Users/ceo/Desktop/MachineLearning/images.csv', 'r+') as infile:
infile.readline()
for line in infile.readlines():
line = line.split(',')
listing_id = line[0]
photos = line[1].split('|')
interest_level = line[2].replace('\n','')
listing_photos[listing_id] = (interest_level, photos)
cntr = 0
import re
for dirpath, dirnames, _ in os.walk(rootdir):
for dname in dirnames:
if dname in listing_photos.keys():
lvl, pps = listing_photos[dname]
imdir = rootdir + '/' + dname
try:
files = os.listdir(imdir)
except:
continue
#print imdir
for f in files:
lvldir = lvldirs[lvl]
#print 'moving',imdir + '/' + f,'to',lvldir
shutil.copy(imdir + '/' + f, lvldir)
print cntr
In [13]:
print len(listing_photos.keys())