1个回答
展开全部
每个文件或者文件夹创建日期和最后修改日期都不同, 你可以试试根据属性来找到你需要的文件夹
以下代码是我在学习中收集起来的。功能是:获得文件的时间信息. 分别为文件的创建时间,文件上一次访问的时间和上一次修改的时间。
代码:
Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As Long, 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 Const GENERIC_WRITE = &H40000000
Private Const FILE_SHARE_READ = &H1
Private Const OPEN_ALWAYS = 4
Private Const FILE_ATTRIBUTE_NORMAL = &H80
Private Const GENERIC_READ = &H80000000
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 Sub Form_Click()
Dim ss As Long
Dim t1 As FILETIME
Dim t2 As FILETIME
Dim t3 As FILETIME
Dim s1 As SYSTEMTIME
Dim s2 As SYSTEMTIME
Dim s3 As SYSTEMTIME
'下面将要获得文件句柄,注意打开的句柄必须要关闭!!!!!
ss = CreateFile("k:\x.txt", GENERIC_READ Or GENERIC_WRITE, FILE_SHARE_READ, ByVal 0&, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0)
GetFileTime ss, t1, t2, t3 '获得文件的时间信息. 其t1表示文件的创建时间,t2表示文件上一次访问的时间,t3表示文件上一次修改的时间
FileTimeToSystemTime t1, s1 '转换文件格式
Print s1.wYear & "-" & s1.wMonth & "-" & s1.wDay & Space(5) & s1.wHour & ":" & s1.wMinute & ":" & s1.wSecond '输出文件创建时间
FileTimeToSystemTime t2, s2 '转换文件格式
Print s2.wYear & "-" & s2.wMonth & "-" & s2.wDay & Space(5) & s2.wHour & ":" & s2.wMinute & ":" & s2.wSecond '输出最近访问时间
FileTimeToSystemTime t3, s3 '转换文件格式
Print s3.wYear & "-" & s3.wMonth & "-" & s3.wDay & Space(5) & s3.wHour & ":" & s3.wMinute & ":" & s3.wSecond '输出文件修改时间
CloseHandle ss '关闭打开的文件句柄
End Sub
以下代码是我在学习中收集起来的。功能是:获得文件的时间信息. 分别为文件的创建时间,文件上一次访问的时间和上一次修改的时间。
代码:
Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As Long, 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 Const GENERIC_WRITE = &H40000000
Private Const FILE_SHARE_READ = &H1
Private Const OPEN_ALWAYS = 4
Private Const FILE_ATTRIBUTE_NORMAL = &H80
Private Const GENERIC_READ = &H80000000
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 Sub Form_Click()
Dim ss As Long
Dim t1 As FILETIME
Dim t2 As FILETIME
Dim t3 As FILETIME
Dim s1 As SYSTEMTIME
Dim s2 As SYSTEMTIME
Dim s3 As SYSTEMTIME
'下面将要获得文件句柄,注意打开的句柄必须要关闭!!!!!
ss = CreateFile("k:\x.txt", GENERIC_READ Or GENERIC_WRITE, FILE_SHARE_READ, ByVal 0&, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0)
GetFileTime ss, t1, t2, t3 '获得文件的时间信息. 其t1表示文件的创建时间,t2表示文件上一次访问的时间,t3表示文件上一次修改的时间
FileTimeToSystemTime t1, s1 '转换文件格式
Print s1.wYear & "-" & s1.wMonth & "-" & s1.wDay & Space(5) & s1.wHour & ":" & s1.wMinute & ":" & s1.wSecond '输出文件创建时间
FileTimeToSystemTime t2, s2 '转换文件格式
Print s2.wYear & "-" & s2.wMonth & "-" & s2.wDay & Space(5) & s2.wHour & ":" & s2.wMinute & ":" & s2.wSecond '输出最近访问时间
FileTimeToSystemTime t3, s3 '转换文件格式
Print s3.wYear & "-" & s3.wMonth & "-" & s3.wDay & Space(5) & s3.wHour & ":" & s3.wMinute & ":" & s3.wSecond '输出文件修改时间
CloseHandle ss '关闭打开的文件句柄
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询