dim aFiles(4) as string dim aDates(4) as date dim i as long,j as long ...for i=0 to 4 aDates(i) = filedatetime(afiles(i)) if i=0 then j = 0 elseif aDates(i) > aDates(j) then j = i end if next debug.print "last file is " & afiles(j) & ", datetime " & adates(j)
同上 dim aFiles(4) as string dim aDates(4) as date dim i as long,j as longaFiles(0)="C\1.txt" aFiles(1)="C\2.txt" aFiles(2)="C\3.txt" aFiles(3)="C\4.txt"for i=0 to 4 aDates(i) = FileDateTime(afiles(i)) if i=0 then j = 0 elseif aDates(i) > aDates(j) then j = i end if next i debug.print "最后一个修改的文件为:" & afiles(j) & " | 修改时间为:" & adates(j)
也可以用FileTimeToSystemTime函数获得 Declare Function FileTimeToSystemTime Lib "kernel32" (lpFileTime As FILETIME, lpSystemTime As SYSTEMTIME) As Long Public Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" (ByVal hFindFile As Long, _ lpFindFileData As WIN32_FIND_DATA) _ As Long Public Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long Public Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" _ (ByVal lpFileName As String, _ lpFindFileData As WIN32_FIND_DATA) _ As LongType 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 Public 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 * MaxLFNPath cShortFileName As String * 14 End Type Public Function Findfile(xstrfilename) As WIN32_FIND_DATA Dim Win32Data As WIN32_FIND_DATA Dim plngFirstFileHwnd As Long Dim plngRtn As Long
plngFirstFileHwnd = FindFirstFile(xstrfilename, Win32Data) ' Get information of file using API call If plngFirstFileHwnd = 0 Then Findfile.cFileName = "Error" ' If file was not found, return error as name Else Findfile = Win32Data ' Else return results End If plngRtn = FindClose(plngFirstFileHwnd) ' It is important that you close the handle for FindFirstFile End Function ‘///////////////////////////////// Dim tFileName As String Dim FileData As WIN32_FIND_DATA Dim fTime As SYSTEMTIME '//Initialise variables tFileName = sPath '//File full path FileData = Findfile(tFileName) Call FileTimeToSystemTime(FileData.ftCreationTime, fTime)'//Determine Creation date and time,then format it Call FileTimeToSystemTime(FileData.ftLastWriteTime, fTime)'//Determine Last Modified date and time Call FileTimeToSystemTime(FileData.ftLastAccessTime, fTime)'//Determine Last accessed date (note no time is recorded)
dim aDates(4) as date
dim i as long,j as long
...for i=0 to 4
aDates(i) = filedatetime(afiles(i))
if i=0 then
j = 0
elseif aDates(i) > aDates(j) then
j = i
end if
next
debug.print "last file is " & afiles(j) & ", datetime " & adates(j)
dim aFiles(4) as string
dim aDates(4) as date
dim i as long,j as longaFiles(0)="C\1.txt"
aFiles(1)="C\2.txt"
aFiles(2)="C\3.txt"
aFiles(3)="C\4.txt"for i=0 to 4
aDates(i) = FileDateTime(afiles(i))
if i=0 then
j = 0
elseif aDates(i) > aDates(j) then
j = i
end if
next i
debug.print "最后一个修改的文件为:" & afiles(j) & " | 修改时间为:" & adates(j)
Declare Function FileTimeToSystemTime Lib "kernel32" (lpFileTime As FILETIME, lpSystemTime As SYSTEMTIME) As Long
Public Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" (ByVal hFindFile As Long, _
lpFindFileData As WIN32_FIND_DATA) _
As Long
Public Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long
Public Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" _
(ByVal lpFileName As String, _
lpFindFileData As WIN32_FIND_DATA) _
As LongType 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
Public 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 * MaxLFNPath
cShortFileName As String * 14
End Type
Public Function Findfile(xstrfilename) As WIN32_FIND_DATA
Dim Win32Data As WIN32_FIND_DATA
Dim plngFirstFileHwnd As Long
Dim plngRtn As Long
plngFirstFileHwnd = FindFirstFile(xstrfilename, Win32Data) ' Get information of file using API call
If plngFirstFileHwnd = 0 Then
Findfile.cFileName = "Error" ' If file was not found, return error as name
Else
Findfile = Win32Data ' Else return results
End If
plngRtn = FindClose(plngFirstFileHwnd) ' It is important that you close the handle for FindFirstFile
End Function
‘/////////////////////////////////
Dim tFileName As String
Dim FileData As WIN32_FIND_DATA
Dim fTime As SYSTEMTIME '//Initialise variables
tFileName = sPath '//File full path
FileData = Findfile(tFileName)
Call FileTimeToSystemTime(FileData.ftCreationTime, fTime)'//Determine Creation date and time,then format it
Call FileTimeToSystemTime(FileData.ftLastWriteTime, fTime)'//Determine Last Modified date and time
Call FileTimeToSystemTime(FileData.ftLastAccessTime, fTime)'//Determine Last accessed date (note no time is recorded)