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

M

Martin Bless

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'
"""
 
M

Matt Gerrans

Are you able change this directories attributes in a command shell or with
explorer? If so, have you tried win32file.SetFileAttributes()?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top