time: Daylight savings confusion
tim--at-- at frontier--dot--.net
Thu Feb 5 07:35:13 CET 2009
On Win XP 64bit, Python 2.6.1 64bit
I am trying to rename files by their creation time.
It seems the time module is too smart for its own good here.
time.localtime(os.path.getctime(f)) returns a value one hour off from
what windows reports for files that were created when Daylight savings
time was in effect (ie when the tm_isdst field is one). I can kludge
it, but am I missing the "right" way to do it?
import os, time
filetypes = (".avi")
skipped = 
for f in os.listdir("."):
root, ext = os.path.splitext(f)
if ext in filetypes:
creation_time = time.localtime(os.path.getctime(f))
newname = time.strftime("%Y-%m-%d_%H%M" + ext, creation_time)
print f, "->", newname
print "These files were skipped:"
for sf in skipped:
More information about the Python-list