Date: 02-16-2022
Return to Index
created by gbSnippets
'From Stuart:
'A PowerTime version of the SetDateTime routine
Sub SetDateTime(fName$, Month As Long, Day As Long, Year As Long, Hour As Long, Minute As Long, Second As Long)
Local hFile&
Local stamptime AS filetime
Local myTime AS IPOWERTIME
myTime = CLASS "POWERTIME"
mytime.newdate year,month,day
mytime.newtime hour,minute,second
mytime.toutc
stamptime.qDateTime = mytime.filetime
hFile& = CreateFile(BYCOPY fName$, ByVal %GENERIC_READ OR %GENERIC_WRITE, _
ByVal 0, ByVal %NULL, ByVal %OPEN_ALWAYS, ByVal %FILE_ATTRIBUTE_NORMAL, ByVal %NULL) 'get handle
SetFileTime ByVal hFile&, ByVal %NULL, ByVal %NULL, stamptime 'Set file time
CloseHandle hfile&
End Sub
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
%IDC_SetDate = 500
Global hDlg As Dword
Function PBMain() As Long
Dialog New Pixels, 0, "Set Date_Time",300,300,240,140, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, %IDC_SetDate,"Set Date_Time", 50,25,140,25
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case Cb.Msg
Case %WM_Command
Select Case Cb.Ctl
Case %IDC_SetDate
SetDateTime EXE.Path$ + "text.txt",1,1,2011,1,1,1 'm-d-y-h-m-s
End Select
End Select
End Function
Sub SetDateTime(fName$, Month As Long, Day As Long, Year As Long, Hour As Long, Minute As Long, Second As Long)
Local hFile&, LocalTime, StampTime As FileTime, SysTime As SystemTime
SysTime.wYear = Year : SysTime.wMonth = Month : SysTime.wDay = Day
SysTime.wHour = Hour : SysTime.wMinute = Minute : SysTime.wSecond = Second
hFile& = CreateFile(ByCopy fName$, ByVal %GENERIC_READ Or %GENERIC_WRITE, _
ByVal 0, ByVal %NULL, ByVal %OPEN_ALWAYS, ByVal %FILE_ATTRIBUTE_NORMAL, ByVal %NULL) 'get handle
SystemTimeToFileTime SysTime, LocalTime 'Convert system date/time to file structure.
LocalFileTimeToFileTime LocalTime, StampTime 'Convert local FT to UTC (needed by SetFileTime)
SetFileTime ByVal hFile&, ByVal %NULL, ByVal %NULL, StampTime 'Set file time
CloseHandle hFile&
End Sub
'gbs_01103
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm