change mtime of directory under windows

Wolfgang Strobl wks000 at t-online.de
Tue Dec 17 15:21:07 EST 2002


stojek at part-gmbh.de (Marcus Stojek):

>Hi,
>can anybody tell me please how to change mtime and/or atime for
>a directory under windows.

Like so:

from win32file import *
from pywintypes import Time
import time
x=CreateFile(r"f:\scratch\testdir",GENERIC_READ+GENERIC_WRITE,
    FILE_SHARE_WRITE,None,OPEN_EXISTING,FILE_FLAG_BACKUP_SEMANTICS,0)

i,c,a,w= GetFileTime(x)

print "create",c,"access",a,"write",w

SetFileTime(x,Time(int(c)-24*3600),Time(int(c)-12*3600),Time(int(c)
    -3*3600))


>
>os.utime(dir,(mtime,atime)) doesn't work (Permission denied)
>win32file.SetFileTime(dir,mtime) doesn't work either, because dir is
>no file handle
>
>I didn't find anything useful.

FLAG_BACKUP_SEMANTICS is the key you missed



-- 
Thank you for observing all safety precautions



More information about the Python-list mailing list