Over the weekend I tried out the new, alternate form of DIR$()
I wanted to see if I could display the various Dates via the DIRDATA structure. Someone else had written a GetFileDateTime() function that seemed pretty applicable, but the FUNCTION takes a FileTime structure as its parameter, and the DIRDATA structure's dates are Quads.
Here's the FUNCTION, with thanks to the original author. (I made minor changes to the format of the return string.)
In my simplistic coding style, here's what I did in order to make it work:
It works, but I'd appreciate feedback - is there a better or simpler way?
Thanks,
-JohnM
Code:
file$ = DIR$(mask$ [, [ONLY] attribute&, TO DirDataVar])
Here's the FUNCTION, with thanks to the original author. (I made minor changes to the format of the return string.)
Code:
'------------------------------------------------------------ Function GetFileDateTime(dt As FILETIME) As String Local lpsystime As SYSTEMTIME Local szDate As Asciiz * 64 ' date buffer, %LDT_SIZE = 64 bytes Local szTime As Asciiz * 64 ' time buffer, %LDT_SIZE = 64 bytes 'convert given date to correct format Call FileTimeToLocalFileTime(dt, dt) Call FileTimeToSystemTime(dt, lpsystime) Call GetDateFormat (%LOCALE_USER_DEFAULT, %NULL, _ ByVal VarPtr(lpsystime), "yyyy'-'MM'-'dd", szDate, SizeOf(szDate)) ' ByVal VarPtr(lpsystime), "yyyy'/'MM'/'dd", szDate, SizeOf(szDate)) Call GetTimeFormat (%LOCALE_USER_DEFAULT, %TIME_FORCE24HOURFORMAT, _ ByVal VarPtr(lpsystime), "HH':'mm':'ss" , szTime, SizeOf(szTime)) 'Function = szDate & " " & szTime Function = szDate & $Spc & szTime End Function
In my simplistic coding style, here's what I did in order to make it work:
Code:
#Compile Exe #Dim All #Include "win32api.inc" 'DIR$ equates %NORMAL = 0 %HIDDEN = 2 %SYSTEM = 4 %VLABEL = 8 %SUBDIR = 16 Union ftUnion 'for use with PB's new DIR$(..., TO DirData_var) q As Quad ft As FILETIME End Union Function PBMain () As Long Local FileData As DIRDATA, sResult As String sResult = Dir$("E:\INFO - PB\_ FORUMS - PB support website\Forum 7 - Source Code", %SUBDIR, To FileData) MsgBox FileData.FileName Local ftq As ftUnion 'DIRDATA's dates are QUADS; convert to FileTime -->> ftq.q vs ftq.ft ftq.q = FileData.CreationTime 'load the QUAD into the union's quad member MsgBox GetFileDateTime(ftq.ft) 'pass it as a FileTime param End Function
Thanks,
-JohnM
Comment