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

不知道文件夹名,求各位高手帮忙,谢谢!... 不知道文件夹名,求各位高手帮忙,谢谢! 展开
 我来答
zengwanbo
2011-12-03 · 超过30用户采纳过TA的回答
知道答主
回答量:80
采纳率:0%
帮助的人:43.9万
展开全部
每个文件或者文件夹创建日期和最后修改日期都不同, 你可以试试根据属性来找到你需要的文件夹
以下代码是我在学习中收集起来的。功能是:获得文件的时间信息. 分别为文件的创建时间,文件上一次访问的时间和上一次修改的时间。
代码:

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
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式