VB中如何实现在一个指定路径中查找到最后创建的文件夹呢?然后获取文件夹名字到文本框里面。

不知道文件夹名,求各位高手帮忙,谢谢!

每个文件或者文件夹创建日期和最后修改日期都不同, 你可以试试根据属性来找到你需要的文件夹
以下代码是我在学习中收集起来的。功能是:获得文件的时间信息. 分别为文件的创建时间,文件上一次访问的时间和上一次修改的时间。
代码:

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
温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网