Date: 02-16-2022
Return to Index
created by gbSnippets
'The PowerBASIC Dir$ statement will return a DirData structure with file info.
'The FileTimeToLocalFileTime and FileTimeToSystemTime API convert the DirData.
'Format$ is used to format the strings into standard date/time formats
'Primary Code:
'Credit: Jose Roca
Function GetFileLastWriteTime(FilePattern$) as String
Local FileInfo As DirData, temp$, lft as FileTime, st AS SystemTime
temp$ = Dir$ (FilePattern$ To FileInfo)
FileTimeToLocalFileTime(ByVal VarPTR(FileInfo.LastWriteTime), lft)
FileTimeToSystemTime(lft, st)
Function = Format$(st.wMonth, "##")+"/"+Format$(st.wDay, "##")+"/"+Format$(st.wYear) + " " + _
Format$(st.wHour, "##")+":"+Format$(st.wMinute, "##")+":"+Format$(st.wSecond)
End Function
'Here's the description of the DirData structure. It' built into PowerBASIC so you
'do not have to include it in your source code.
Type DirData
FileAttributes AS Dword
CreationTime AS QUAD
LastAccessTime AS QUAD
LastWriteTime AS QUAD
FileSizeHigh AS Dword
FileSizeLow AS Dword
Reserved0 AS Dword
Reserved1 AS Dword
FileName As AsciiZ * 260
ShortName As AsciiZ * 14
End Type
'The function above can be applied to .CreationTime, .LastAccessTime, or .LastWriteTime.
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
Global hDlg As Dword
Function PBMain() As Long
Dialog New Pixels, 0, "Test Code",300,300,200,200, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 100,"Push", 50,10,100,20
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
If CB.Msg = %WM_Command AND CB.Ctl = 100 AND CB.Ctlmsg = %BN_Clicked Then
MsgBox GetFileLastWriteTime("myfile.txt")
End If
End Function
Function GetFileLastWriteTime(FilePattern$) As String
Local FileInfo As DirData, temp$, lft As FileTime, st As SystemTime
temp$ = Dir$ (FilePattern$ To FileInfo)
FileTimeToLocalFileTime(ByVal VarPTR(FileInfo.LastWriteTime), lft)
FileTimeToSystemTime(lft, st)
Function = "myfile.txt" + $crlf + $crlf + _
Format$(st.wMonth, "##")+"/"+Format$(st.wDay, "##")+"/"+Format$(st.wYear) + " " + _
Format$(st.wHour, "##")+":"+Format$(st.wMinute, "##")+":"+Format$(st.wSecond)
End Function
'gbs_00148
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm