Re: file date/time

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



"Dave O." <nobody@xxxxxxxxxxx> wrote in message news:OJAZBRwwHHA.4544@xxxxxxxxxxxxxxxxxxxxxxx
What's really weird is that as far as I can tell it is very difficult if not impossible to read the Accessed date without accessing the file which in turn updates the Accessed date, so the date will always be the current time.

The FindNextFile API calls will return it:
Private Const MAX_PATH = 260
Private Const INVALID_HANDLE_VALUE = -1
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
Private Type WIN32_FIND_DATA
dwFileAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String * MAX_PATH
cAlternate As String * 14
End Type
Private Declare Function FindFirstFile Lib "kernel32" _
Alias "FindFirstFileA" (ByVal lpFileName As String, _
ByRef lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindNextFile Lib "kernel32" _
Alias "FindNextFileA" (ByVal hFindFile As Long, _
ByRef lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindClose Lib "kernel32" _
(ByVal hFindFile As Long) As Long
Private Declare Function FileTimeToSystemTime Lib "kernel32" _
(ByRef lpFileTime As FILETIME, ByRef lpSystemTime As SYSTEMTIME) As Long
Private Declare Function FileTimeToLocalFileTime Lib "kernel32" _
(ByRef lpFileTime As FILETIME, ByRef lpLocalFileTime As FILETIME) As Long

Sub Main()
ShowFiles "C:\"
End Sub

Public Sub ShowFiles(ByVal DirPath As String)
Dim hFind As Long ' handle to "find" in progress
Dim fdata As WIN32_FIND_DATA
Dim uFT As FILETIME
Dim uST As SYSTEMTIME
Dim sName As String
Dim x As Long
On Error Resume Next ' hack to avoid GPF in FindFirstFile
sName = Dir$(EndSlash(DirPath) & "*.*", vbSystem Or vbHidden Or vbDirectory)
On Error GoTo 0 ' we must have access...
hFind = FindFirstFile(EndSlash(DirPath) & "*.*", fdata)
If hFind <> INVALID_HANDLE_VALUE Then ' no files found
Do
sName = fdata.cFileName
x = InStr(1, sName, vbNullChar)
If x > 0 Then sName = Left$(sName, x - 1)
x = FileTimeToLocalFileTime(fdata.ftLastAccessTime, uFT)
x = FileTimeToSystemTime(uFT, uST)
With uST
Debug.Print sName, DateSerial(.wYear, .wMonth, .wDay) + TimeSerial(.wHour, .wMinute, .wSecond)
End With
Loop While FindNextFile(hFind, fdata) <> 0
hFind = FindClose(hFind)
End If
End Sub

Private Function EndSlash(ByVal PathIn As String) As String
' used to ensure path ends with backslash
If Right$(PathIn, 1) = "\" Then
EndSlash = PathIn
Else
EndSlash = PathIn & "\"
End If
End Function

.



Relevant Pages

  • Re: Alpha search to load a list box
    ... Dim strTemp As String ... Private Sub LblAlpha_MouseDown(Button As Integer, Shift As Integer, X ... Dim StartX As Long, WidthX As Long ... Private Declare Function apiSelectObject Lib "gdi32" Alias ...
    (microsoft.public.access.formscoding)
  • Re: Alpha search to load a list box
    ... Dim strTemp As String ... Private Declare Function apiSelectObject Lib "gdi32" Alias ... Dim newfont As Long ' Handle to our Font Object we created. ...
    (microsoft.public.access.formscoding)
  • ListView.SelectedItem cannot be modified
    ... Dim objFind As LV_FINDINFO ... Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd ... lpClassName As String, ByVal lpWindowName As String) As Long ... 'CompareDates: This is the sorting routine that gets passed to the ...
    (microsoft.public.vb.controls)
  • Re: Need to call windows scheduler.
    ... Private Declare Function OpenSCManager Lib "advapi32.dll" Alias ... "OpenSCManagerA" (ByVal lpMachineName As String, ... Dim lhSCM As Long, lhService As Long, sState As String, lReturn ...
    (microsoft.public.access.formscoding)
  • Re: changing vbOKCancel button title
    ... Private Declare Function GetCurrentThreadId Lib "kernel32" _ ... ByVal lpCaption As String, _ ... Dim mbFlags2 As VbMsgBoxStyle ... SetDlgItemText wParam, vbAbort, But1 ...
    (microsoft.public.excel.misc)