12-30-2005, 12:11 PM
Function SetFileTimes
;/
function $sFile DATE'tMod [DATE'tCreat] [DATE'tAccess] [utc]
;Sets file times.
;Use 0 for times that should not be changed.
;If utc is nonzero, times are interpreted as UTC times. Default - local times.
;EXAMPLE
;;set file modified time to current time
;DATE d.getclock ;;get current local time
;SetFileTimes "$desktop$\test.txt" d
dll kernel32 #CreateFile $lpFileName dwDesiredAccess dwShareMode SECURITY_ATTRIBUTES*lpSecurityAttributes dwCreationDisposition dwFlagsAndAttributes hTemplateFile
dll kernel32 #SetFileTime hFile FILETIME*lpCreationTime FILETIME*lpLastAccessTime FILETIME*lpLastWriteTime
def FILE_WRITE_ATTRIBUTES (0x100)
def OPEN_EXISTING 3
int hfile=CreateFile(_s.expandpath(sFile) FILE_WRITE_ATTRIBUTES 0 0 OPEN_EXISTING 0 0)
if(hfile=-1) end _s.dllerror()
FILETIME ft ftm ftc fta; FILETIME* pftm pftc pfta
if(tMod) pftm=&ftm; tMod.tofiletime(ft); if(utc) ftm=ft; else LocalFileTimeToFileTime &ft &ftm
if(tCreat) pftc=&ftc; tCreat.tofiletime(ft); if(utc) ftc=ft; else LocalFileTimeToFileTime &ft &ftc
if(tAccess) pfta=&fta; tAccess.tofiletime(ft); if(utc) fta=ft; else LocalFileTimeToFileTime &ft &fta
int ok=SetFileTime(hfile pftc pfta pftm)
CloseHandle hfile
if(!ok) end ES_FAILED