Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Change date and time of files
#1
How works SetFileTime?
#2
Code:
Copy      Help
str sFile="$desktop$\test.txt"

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()

DATE d.getclock
FILETIME ft ftutc
d.tofiletime(ft)
LocalFileTimeToFileTime &ft &ftutc
SetFileTime hfile 0 0 &ftutc

CloseHandle hfile
#3
Thanks.

Happy New Year...
#4
Function SetFileTimes

Code:
Copy      Help
;/
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


Forum Jump:


Users browsing this thread: 1 Guest(s)