-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphotoFolderIdentifier.py
More file actions
32 lines (31 loc) · 1.29 KB
/
photoFolderIdentifier.py
File metadata and controls
32 lines (31 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#! python3 #
# a program that goes through every folder on your hard drive and finds potential photo folders.
import os
from PIL import Image
print('Going through all folders in your directory...')
for foldername, subfolders, filenames in os.walk('C:\\'):
numPhotoFiles = 0
numNonPhotoFiles = 0
for filename in filenames:
try:
# Check if file extension isn't .png or .jpg.
if not (filename.endswith('.png') or filename.endswith('.jpg')):
numNonPhotoFiles += 1
continue # skip to next filename
else:
# Open image file using Pillow.
im = Image.open(os.path.join(foldername, filename))
# Check if width & height are larger than 500.
width, height = im.size
if int(width) > 500 and int(height) > 500:
# Image is large enough to be considered a photo.
numPhotoFiles += 1
else:
# Image is too small to be a photo.
numNonPhotoFiles += 1
except:
continue
# If more than half of files were photos,
# print the absolute path of the folder.
if numPhotoFiles > numNonPhotoFiles:
print(foldername)