"joesu" wrote in message
news:f19de7f.1@WebX.maYIadrTaRb...
> Please post the code you used to generate the information.
> Joe
> --
>
i think this is most of it,
some is in a class mod cmnFile.cls
the calling sub is in a test module.
(some of the declares are for other parts of the class, not all are used in
this example)
'**** this stuff in cls mod
'adapted from example by:
'KPD-Team 2001
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@allapi.net
'as well as info gleaned from msdn
'compare file times
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 Type BY_HANDLE_FILE_INFORMATION
dwFileAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
dwVolumeSerialNumber As Long
nFileSizeHigh As Long
nFileSizeLow As Long
nNumberOfLinks As Long
nFileIndexHigh As Long
nFileIndexLow As Long
End Type
'declare winapi functions
Private Declare Function SearchTreeForFile Lib "IMAGEHLP.DLL" (ByVal
lpRootPath As String, ByVal lpInputName As String, ByVal lpOutputName As
String) As Long
Private Declare Function GetFileInformationByHandle Lib "kernel32" (ByVal
hFile As Long, lpFileInformation As BY_HANDLE_FILE_INFORMATION) As Long
Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA"
(ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal
dwShareMode As Long, lpSecurityAttributes As Any, ByVal
dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal
hTemplateFile As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long)
As Long
Private Declare Function GetFileTime Lib "kernel32" (ByVal hFile As Long,
lpCreationTime As FILETIME, lpLastAccessTime As FILETIME, lpLastWriteTime As
FILETIME) As Long
Private Declare Function FileTimeToSystemTime Lib "kernel32" (lpFileTime As
FILETIME, lpSystemTime As SYSTEMTIME) As Long
Private Declare Function FileTimeToLocalFileTime Lib "kernel32" (lpFileTime
As FILETIME, lpLocalFileTime As FILETIME) As Long
Private Declare Function SystemTimeToFileTime Lib "kernel32" (lpSystemTime
As SYSTEMTIME, lpFileTime As FILETIME) As Long
Private Declare Function CompareFileTime Lib "kernel32" (lpFileTime1 As
FILETIME, lpFileTime2 As FILETIME) As Long
Private Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA"
(ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA"
(ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function GetFileAttributes Lib "kernel32" Alias
"GetFileAttributesA" (ByVal lpFileName As String) As Long
Private Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long)
As Long
Public Sub GetFileTimes(ByVal sFileName As String, ByRef colRtn As
Collection)
'file handle
Dim lngFhndl As Long
'file times
Dim ftCreated As FILETIME
Dim ftLastAccess As FILETIME
Dim ftSaved As FILETIME
'local time
Dim ftlCreated As FILETIME
Dim ftlLastAccess As FILETIME
Dim ftlSaved As FILETIME
'system time
Dim ftsCreated As SYSTEMTIME
Dim ftsLastAccess As SYSTEMTIME
Dim ftsSaved As SYSTEMTIME
'get handle
lngFhndl = GetFileHandle(sFileName)
'fill in filetime structures
GetFileTime lngFhndl, ftCreated, ftLastAccess, ftSaved
'close handle
CloseFile (lngFhndl)
'Convert the file times to the local file time
FileTimeToLocalFileTime ftCreated, ftlCreated
FileTimeToLocalFileTime ftLastAccess, ftlLastAccess
FileTimeToLocalFileTime ftSaved, ftlSaved
'Convert the file times to system file time
FileTimeToSystemTime ftlCreated, ftsCreated
FileTimeToSystemTime ftlLastAccess, ftsLastAccess
FileTimeToSystemTime ftlSaved, ftsSaved
'cant pass a systemtime structure so convert to string
Dim sCreated As String
Dim sAccessed As String
Dim sSaved As String
'add strings to byref return collection argument/parameter
colRtn.Add GetTimeString(ftsCreated)
colRtn.Add GetTimeString(ftsLastAccess)
colRtn.Add GetTimeString(ftsSaved)
End Sub
Private Function GetTimeString(ByRef sFileTime As SYSTEMTIME) As String
Dim sTime As String
sTime = Str$(sFileTime.wMonth) _
+ "/" + LTrim(Str$(sFileTime.wDay)) _
+ "/" + LTrim(Str$(sFileTime.wYear)) _
+ " " + LTrim(Str$(sFileTime.wHour)) _
+ ":" + LTrim(Str$(sFileTime.wMinute)) _
+ ":" + LTrim(Str$(sFileTime.wSecond)) _
+ ":" + LTrim(Str$(sFileTime.wMilliseconds))
GetTimeString = sTime
End Function
Private Function GetFileHandle(ByVal sFileName As String) As Long
Dim hFile As Long
'create a handle to the file
hFile = CreateFile(sFileName, 0, 0, ByVal 0&, OPEN_EXISTING, 0, ByVal
0&)
'return file handle
GetFileHandle = hFile
End Function
'******end of cls mod
'*********this in test module
Sub testgetfiles()
Dim cd As cmnDebug
Set cd = New cmnDebug
cd.DebugOn = True
Dim cF As cmnFile
Set cF = New cmnFile
Dim sDirA As String
sDirA = "C:\0\0code\vb\"
Dim vRtn As Variant
'get list of files
vRtn = cF.GetFilesAPI(sDirA, "*")
Dim lb As Integer
Dim ub As Integer
lb = LBound(vRtn)
ub = UBound(vRtn)
Dim iNumfiles As Integer
iNumfiles = ub - lb + 1
Dim icount As Integer
icount = 0
Dim i As Integer
Dim sCreatedA As String
Dim sAccessedA As String
Dim sSavedA As String
Dim j As Integer
For i = lb To ub
'fresh collection ea time
Dim colRes As New Collection
cF.GetFileTimes sDirA & vRtn(i), colRes
sCreatedA = colRes(1)
sAccessedA = colRes(2)
sSavedA = colRes(3)
If sCreatedA > sSavedA Then
icount = icount + 1
End If
'clear collection
Set colRes = Nothing
Next
cd.dp sDirA & vRtn(i - 1)
cd.dp "Created: " & sCreatedA
cd.dp "Last Accessed: " & sAccessedA
cd.dp "Last saved: " & sSavedA
cd.dp "out of " & iNumfiles & " files, there were " & icount & " with
saved date before created date"
End Sub
cd.dp is basically debug.print with a boolean switch for on or off.
(in another .cls)
fwiw I think wayne is right about the copying of a file updating it's
created date, but not saved date. which explains my results.
thanks all
Mark