How can I change the timestamps of directories? (os.utime(), WinXP)

Martin Bless m.bless at gmx.de
Thu Dec 9 11:05:44 EST 2004


I'm working on a backup scheme that looks at modification times. To
run some tests I'd like to be able to set the modification time of
directories (WinXPsp2, Python-2.3.4)

os.utime() works well with files but throws a permission error with
directories. See code below.

Q: Can this be done via the os-module?
Q: Is it possible at all? Somebody knows?

Thanks,

mb - Martin Bless


"""
Trying to the timestamps of a directory
"""
import sys, os, stat, datetime, time
today = datetime.datetime.now()
pastday = today - datetime.timedelta(days=11)
atime = int(time.mktime(pastday.timetuple()))
mtime = atime
times = (atime,mtime)
path = os.path.normpath(r'c:/dummydir')
os.utime(path,times)

""" throws error:
OSError: [Errno 13] Permission denied: 'c:\\dummydir'
"""





More information about the Python-list mailing list