License New BSD license
Lines 17
Keywords
cell phone (1) file management (6) photo (1)
Included in this Library
Permissions
Viewable by Everyone
Editable by All Siafoo Users
Hide
Writing an article is easy - try our reStructured Text demo Join Siafoo Now or Learn More

Fix Creation Dates Based on File Names Atom Feed 0

In Brief Takes files with names in the form MM-DD-YY (such as the images created by my cell phone camera) and changes their creation dates to match that date (and sets the creation time to 9 pm). This makes image-handling programs like iPhoto sort everything correctly.
# 's
 1#!/usr/bin/env python
2
3# Copyright 2008 David Isaacson
4# BSD License
5
6import sys
7import os
8import re
9
10for path in sys.argv[1:]:
11 print os.path.abspath(path)
12 file = os.path.basename(path)
13 match = re.match('(\d\d)-(\d\d)-(\d\d)',file)
14 if match is None: continue
15 month, date, year = match.groups()
16
17 command = "touch -t 20%s%s%s2100 %s" %(year,month,date,re.escape(path))
18 print command
19 os.system(command)
20
21

Takes files with names in the form MM-DD-YY (such as the images created by my cell phone camera) and changes their creation dates to match that date (and sets the creation time to 9 pm). This makes image-handling programs like iPhoto sort everything correctly.