VB6.0中怎样遍历一个路径下的所有内容?
同题。想做一个搜索一个路径下所有文件、文件夹的程序然后把搜索结果列出来怎么实现呢?能给出代码就更好了,有代码一定再加分如果嫌麻烦那就讲一讲思路吧有程序的源码发到我的QQ邮...
同题。
想做一个搜索一个路径下所有文件、文件夹的程序
然后把搜索结果列出来
怎么实现呢?
能给出代码就更好了,有代码一定再加分
如果嫌麻烦 那就讲一讲思路吧
有程序的源码发到我的QQ邮箱吧
vnvlyp@vip.qq.com
谢谢了!!! 展开
想做一个搜索一个路径下所有文件、文件夹的程序
然后把搜索结果列出来
怎么实现呢?
能给出代码就更好了,有代码一定再加分
如果嫌麻烦 那就讲一讲思路吧
有程序的源码发到我的QQ邮箱吧
vnvlyp@vip.qq.com
谢谢了!!! 展开
4个回答
展开全部
'看申明,选择遍历文件或者文件夹
Public Function sDirTraV30(ByVal strpath As String, ByRef strFiles() As String, Optional isTraWholeDir As Boolean = True, Optional isRecDir As Boolean = False) As Long
Dim lmax As Long
Dim strTmp As String
Dim sDirList() As String
Dim l As Long
Dim c As Long
Dim i As Integer
If Right$(strpath, 1) <> "\" Then strpath = strpath & "\"
On Error Resume Next
strTmp = Dir(strpath, vbNormal Or vbReadOnly Or vbHidden Or vbSystem Or vbVolume Or vbDirectory)
c = 0
If Len(strTmp) > 0 And isRecDir Then
lmax = UBound(strFiles) + 1
ReDim Preserve strFiles(lmax)
strFiles(lmax) = strpath
c = c + 1
End If
ReDim sDirList(-1 To -1)
Do While Len(strTmp) > 0
If GetAttr(strpath & strTmp) And vbDirectory Then If Asc(Left(strTmp, 1)) <> 46 Then
If isTraWholeDir Then
lmax = UBound(sDirList) + 1
ReDim Preserve sDirList(-1 To lmax)
sDirList(lmax) = strpath & strTmp
Else
lmax = UBound(strFiles) + 1
ReDim Preserve strFiles(lmax)
strFiles(lmax) = strpath & strTmp
c = c + 1
End If
End If
Else
lmax = UBound(strFiles) + 1
ReDim Preserve strFiles(lmax)
strFiles(lmax) = strpath & strTmp
c = c + 1
End If
strTmp = Dir
Loop
If isTraWholeDir Then
For l = 0 To UBound(sDirList)
c = c + sDirTraV30(sDirList(l), strFiles(), isTraWholeDir, isRecDir)
Next
End If
sDirTraV30 = c
End Function
'我一个小程序中的一段代码,使用了这个函数(遍历文件夹),给你看看用法。
Private Sub btnLogin_Click(Index As Integer)
Dim strFiles() As String
Dim tempStr As String
Dim lstStr() As String
Select Case Index
Case 0
Picture1(1).Visible = False
Picture1(2).Visible = False
Picture1(3).Visible = False
Picture1(0).Visible = True
Case 1
Picture1(0).Visible = False
Picture1(2).Visible = False
Picture1(3).Visible = False
Picture1(1).Visible = True
Case 2
Picture1(1).Visible = False
Picture1(0).Visible = False
Picture1(3).Visible = False
Picture1(2).Visible = True
If sDirTraV30(App.Path & "\Data\HX\setting\", strFiles(), False, False) = 0 Then Exit Sub
With lstJS
.ListItems.Clear
.ColumnHeaders.Clear
.View = lvwReport
.ColumnHeaders.Add , , "序号", 550
.ColumnHeaders.Add , , "已存在角色名称", lstJS.Width - 580
.ColumnHeaders(2).Alignment = lvwColumnCenter
End With
For i = 0 To UBound(strFiles)
strFiles(i) = Replace(strFiles(i), App.Path & "\Data\HX\setting\", "")
If StrComp(strFiles(i), "Default", vbTextCompare) <> 0 Then
If tempStr = "" Then
tempStr = strFiles(i)
Else
tempStr = tempStr & "," & strFiles(i)
End If
End If
Next
lstStr = Split(tempStr, ",")
For i = 0 To UBound(lstStr)
Set ListItemTemp = lstJS.ListItems.Add(, , i + 1)
ListItemTemp.SubItems(1) = lstStr(i)
Next
Case 3
Picture1(1).Visible = False
Picture1(2).Visible = False
Picture1(0).Visible = False
Picture1(3).Visible = True
End Select
End Sub
Public Function sDirTraV30(ByVal strpath As String, ByRef strFiles() As String, Optional isTraWholeDir As Boolean = True, Optional isRecDir As Boolean = False) As Long
Dim lmax As Long
Dim strTmp As String
Dim sDirList() As String
Dim l As Long
Dim c As Long
Dim i As Integer
If Right$(strpath, 1) <> "\" Then strpath = strpath & "\"
On Error Resume Next
strTmp = Dir(strpath, vbNormal Or vbReadOnly Or vbHidden Or vbSystem Or vbVolume Or vbDirectory)
c = 0
If Len(strTmp) > 0 And isRecDir Then
lmax = UBound(strFiles) + 1
ReDim Preserve strFiles(lmax)
strFiles(lmax) = strpath
c = c + 1
End If
ReDim sDirList(-1 To -1)
Do While Len(strTmp) > 0
If GetAttr(strpath & strTmp) And vbDirectory Then If Asc(Left(strTmp, 1)) <> 46 Then
If isTraWholeDir Then
lmax = UBound(sDirList) + 1
ReDim Preserve sDirList(-1 To lmax)
sDirList(lmax) = strpath & strTmp
Else
lmax = UBound(strFiles) + 1
ReDim Preserve strFiles(lmax)
strFiles(lmax) = strpath & strTmp
c = c + 1
End If
End If
Else
lmax = UBound(strFiles) + 1
ReDim Preserve strFiles(lmax)
strFiles(lmax) = strpath & strTmp
c = c + 1
End If
strTmp = Dir
Loop
If isTraWholeDir Then
For l = 0 To UBound(sDirList)
c = c + sDirTraV30(sDirList(l), strFiles(), isTraWholeDir, isRecDir)
Next
End If
sDirTraV30 = c
End Function
'我一个小程序中的一段代码,使用了这个函数(遍历文件夹),给你看看用法。
Private Sub btnLogin_Click(Index As Integer)
Dim strFiles() As String
Dim tempStr As String
Dim lstStr() As String
Select Case Index
Case 0
Picture1(1).Visible = False
Picture1(2).Visible = False
Picture1(3).Visible = False
Picture1(0).Visible = True
Case 1
Picture1(0).Visible = False
Picture1(2).Visible = False
Picture1(3).Visible = False
Picture1(1).Visible = True
Case 2
Picture1(1).Visible = False
Picture1(0).Visible = False
Picture1(3).Visible = False
Picture1(2).Visible = True
If sDirTraV30(App.Path & "\Data\HX\setting\", strFiles(), False, False) = 0 Then Exit Sub
With lstJS
.ListItems.Clear
.ColumnHeaders.Clear
.View = lvwReport
.ColumnHeaders.Add , , "序号", 550
.ColumnHeaders.Add , , "已存在角色名称", lstJS.Width - 580
.ColumnHeaders(2).Alignment = lvwColumnCenter
End With
For i = 0 To UBound(strFiles)
strFiles(i) = Replace(strFiles(i), App.Path & "\Data\HX\setting\", "")
If StrComp(strFiles(i), "Default", vbTextCompare) <> 0 Then
If tempStr = "" Then
tempStr = strFiles(i)
Else
tempStr = tempStr & "," & strFiles(i)
End If
End If
Next
lstStr = Split(tempStr, ",")
For i = 0 To UBound(lstStr)
Set ListItemTemp = lstJS.ListItems.Add(, , i + 1)
ListItemTemp.SubItems(1) = lstStr(i)
Next
Case 3
Picture1(1).Visible = False
Picture1(2).Visible = False
Picture1(0).Visible = False
Picture1(3).Visible = True
End Select
End Sub
展开全部
api函数中有一个函数叫“FINDNEXTFILES”函数,用这个函数就可以了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
用dir()函数就可以遍历所有文件,
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你留下邮箱地址,我给你发你所需的搜索工具(附VB代码)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询