setting directory mod date

MRAB google at mrabarnett.plus.com
Tue Mar 24 20:39:11 EDT 2009


Gabriel Genellina wrote:
> En Tue, 24 Mar 2009 19:10:50 -0300, MRAB <google at mrabarnett.plus.com> 
> escribió:
> 
>> jyoung79 at kc.rr.com wrote:
>>> I've got some Python code (2.5.1) that's compressing folders on a 
>>> Windows machine.  When the directories get compressed, their 
>>> modification date changes.  Is it possible to grab the modification 
>>> date of the folder before it's compressed, and then set it's 
>>> modification date back to it's original state after it's compressed?  
>>> I've been reading different articles on-line about this, but nothing 
>>> looks very promising.  I haven't tested os.utime() or win32file since 
>>> others have said these won't work correctly with folders on Windows XP.
>>>
>> I've just tried it. os.utime() _does_ work correctly on folders.
> 
> But not on Python 2.5 :(
> 
Ah, missed that bit (I used Python 2.6.1). Sorry!

> Using the pywin32 package:
> 
> py> os.stat("cuchi")
> (16895, 0L, 0, 0, 0, 0, 0L, 1237259905, 1235809285, 1235809278)
> py> from win32file import *
> py> hFile = CreateFile("cuchi", GENERIC_WRITE, 0,
> ...                                 None, OPEN_EXISTING,
> ...                                 FILE_FLAG_BACKUP_SEMANTICS, None)
> py> import time
> py> import pywintypes
> py> t = pywintypes.Time(time.localtime())
> py> win32file.SetFileTime(hFile, t, t, t)
> py> CloseHandle(hFile)
> py> os.stat("cuchi")
> (16895, 0L, 0, 0, 0, 0, 0L, 1237940110, 1237940110, 1237940110)
> 




More information about the Python-list mailing list