vb 怎样检索指定文件夹内所有文件,文件名显示在Label上。(好像需要用timer控件吧!)
展开全部
‘用listbox控件,label多文件怎么写?
Private Sub Command1_Click()
Dim arr(), i As Long
If getfilename("d:\abc", arr) Then
For i = LBound(arr) To UBound(arr)
List1.AddItem arr(i)
Next
End If
End Sub
Function getfilename(pathname As String, temp) As Boolean
Dim sf, n As Long
pathname = pathname & IIf(Right(pathname, 1) = "\", "", "\")
sf = Dir(pathname, vbDirectory)
If Len(sf) = 0 Then
Exit Function
End If
Do While sf <> ""
If sf <> "." And sf <> ".." Then
n = n + 1
ReDim Preserve temp(1 To n)
temp(n) = pathname & sf
End If
sf = Dir()
Loop
If n > 0 Then getfilename = True
End Function
Private Sub Command1_Click()
Dim arr(), i As Long
If getfilename("d:\abc", arr) Then
For i = LBound(arr) To UBound(arr)
List1.AddItem arr(i)
Next
End If
End Sub
Function getfilename(pathname As String, temp) As Boolean
Dim sf, n As Long
pathname = pathname & IIf(Right(pathname, 1) = "\", "", "\")
sf = Dir(pathname, vbDirectory)
If Len(sf) = 0 Then
Exit Function
End If
Do While sf <> ""
If sf <> "." And sf <> ".." Then
n = n + 1
ReDim Preserve temp(1 To n)
temp(n) = pathname & sf
End If
sf = Dir()
Loop
If n > 0 Then getfilename = True
End Function
更多追问追答
追问
分别显示,每个0.2秒或几秒显示一个,就像Windows搜索一样!
追答
Private Sub Command1_Click()
Dim arr(), i As Long, t
Command1.Enabled = False
If getfilename("d:\abc", arr) Then
Label1.AutoSize = True
For i = LBound(arr) To UBound(arr)
Label1 = arr(i)
t = Timer
Do Until Timer - t > 0.2
DoEvents
Loop
Next
End If
Command1.Enabled = True
End Sub
Function getfilename(pathname As String, temp) As Boolean
Dim sf, n As Long
pathname = pathname & IIf(Right(pathname, 1) = "\", "", "\")
sf = Dir(pathname, vbDirectory)
If Len(sf) = 0 Then
Exit Function
End If
Do While sf ""
If sf "." And sf ".." Then
n = n + 1
ReDim Preserve temp(1 To n)
temp(n) = pathname & sf
End If
sf = Dir()
Loop
If n > 0 Then getfilename = True
End Function
展开全部
用个filelist控件直接循环就可以了
追问
具体是什么????
追答
For i = 0 To File1.ListCount
label1.caption= File1.List(i)
中间延时一下
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
学习一下
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询