import sys, os, time sys.exit() # hardcode the changed timestamp below stime1 = "08/24/2010 06:24 PM" # everyday food video stime2 = "06/29/2010 04:31 PM" # neely video ts = time.strptime(stime2, "%m/%d/%Y %I:%M %p") print ts print time.mktime(ts) setTimeVal = time.mktime(ts) print sys.argv[0] print len(sys.argv) if len(sys.argv) < 2: print "usage ", sys.argv[0], " <filename>" sys.exit(-1) filename = sys.argv[1] ts = os.stat(filename) print ts os.utime(filename, (setTimeVal,setTimeVal))
My tech exploits. Nah... closer to a tech diary, and work log, so if I forget something, but know I forgot, I'll maybe be able to look it up here. And as a bonus, perhaps someone out there will find it useful or interesting. As is only fair, being nearly all the information put here was gleaned from elsewhere on the web.
Friday, October 28, 2011
Change file timestamp
A crude python script to change modify/access file timestamps, after the new NAS would incorrectly change them to current time. Note: only changes modify and access time. File create time cannot be changed by standard python calls. From quick online research, it is suggested lower level, OS dependent, privileged system calls or crudely changing the system clock is required to change creation times.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment