-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrename.py
More file actions
40 lines (29 loc) · 713 Bytes
/
rename.py
File metadata and controls
40 lines (29 loc) · 713 Bytes
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
33
34
35
36
37
38
39
40
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# rename.py
#
# Copyright 2015 João Ferreira <jpbat@student.dei.uc.pt>
#
import os
import glob
from PIL import Image
def getTimestamp(name):
img = Image.open(name)
exifData = img._getexif()
for k, v in exifData.items():
if k == 36867:
return v
def main():
fileList = glob.glob('*.JPG') + glob.glob('*.jpg') + glob.glob('*.JPEG') + glob.glob('*.jpeg')
renamed = 0
for i in xrange(len(fileList)):
f = fileList[i]
f2 = getTimestamp(f) + '.jpg'
if f2 == f:
continue
print "Renaming", (i+1), "of", len(fileList), "\t", f, "->", f2
renamed += 1
os.rename(f, f2)
print 'Done. Pictures renamed:', renamed
main()