Created
March 11, 2014 08:57
-
-
Save yava555/9481947 to your computer and use it in GitHub Desktop.
Dropbox Camera Uploads rename
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__author__ = 'yava' | |
from PIL import Image | |
from PIL import ExifTags | |
import os | |
import datetime | |
def getImageTime(path): | |
try: | |
img=Image.open(path) | |
exifinfo = img._getexif() | |
if exifinfo !=None: | |
timeStr = exifinfo.get(0x9004) | |
if timeStr!=None: | |
time=datetime.datetime.strptime(timeStr,'%Y:%m:%d %H:%M:%S') | |
return datetime.datetime.strftime(time,'%Y-%m-%d %H.%M.%S') | |
except: | |
return None | |
files= os.listdir("/Users/yava/Dropbox/Camera Uploads") | |
for f in files: | |
if ".jpg" in f or "JPG" in f: | |
oldName="/Users/yava/Dropbox/Camera Uploads/"+f | |
time=getImageTime(oldName) | |
if time !=None: | |
newName= "/Users/yava/Dropbox/Camera Uploads/"+time+".jpg" | |
print newName; | |
os.renames(oldName,newName) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment