Re: file date/time
- From: "Bob Butler" <noway@xxxxxxxxxxx>
- Date: Tue, 10 Jul 2007 08:26:49 -0700
"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
.
- Follow-Ups:
- Re: file date/time
- From: Dave O.
- Re: file date/time
- References:
- Re: file date/time
- From: Dave O.
- Re: file date/time
- Prev by Date: Re: file date/time
- Next by Date: Layered Window
- Previous by thread: Re: file date/time
- Next by thread: Re: file date/time
- Index(es):
Relevant Pages
|