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

Discussion in 'Python' started by Martin Bless, Dec 9, 2004.

  1. Martin Bless

    Martin Bless Guest

    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'
    """
    Martin Bless, Dec 9, 2004
    #1
    1. Advertising

  2. Martin Bless

    Matt Gerrans Guest

    Are you able change this directories attributes in a command shell or with
    explorer? If so, have you tried win32file.SetFileAttributes()?
    Matt Gerrans, Dec 9, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mike
    Replies:
    2
    Views:
    237
  2. Axel Friedrich

    utime bug help?

    Axel Friedrich, Oct 31, 2005, in forum: Ruby
    Replies:
    4
    Views:
    139
    Axel Friedrich
    Nov 2, 2005
  3. Axel Friedrich

    utime: still with bug?

    Axel Friedrich, Mar 1, 2006, in forum: Ruby
    Replies:
    2
    Views:
    106
    Axel Friedrich
    Mar 2, 2006
  4. Matt Scilipoti
    Replies:
    2
    Views:
    194
    Matt Scilipoti
    Jun 6, 2007
  5. Matt Spendlove

    utime a dir and convert Date to Time

    Matt Spendlove, Jan 15, 2008, in forum: Ruby
    Replies:
    3
    Views:
    106
    Siep Korteling
    Jan 15, 2008
Loading...

Share This Page