当前位置:编程学习 > VB >>

VB自动查找功能

VB自动查找(C、D、E等盘)TEXT1中指定的文件夹名称,将找到的文件夹路径添加到TEXT2中。

代码如何实现!

追问:谢谢fontain2的帮助,谢谢,怎么只能扫描C?我要全盘扫描,包括D,E,F

答案:Sub FindDirectory(ByVal Root As String, ByVal target As String)
    Dim DName As String
    Dim StDir As String
    Dim DirList As New Collection
    Dim i As Integer
    StDir = Root
    If Right(StDir, 1) <> "\" Then StDir = StDir & "\"
    i = 1
    Label1.Caption = "Searching:" & StDir
    DoEvents
    DName = Dir(StDir, vbDirectory)
    Do While DName <> ""
        If GetAttr(StDir & DName) And vbDirectory Then
            If DName <> "." And DName <> ".." Then
                If DName = target Then
                    Text2 = Text2 & StDir & DName
                    DoEvents
                End If
                DirList.Add DName, Str(i)
                i = i + 1
            End If
        End If
        DName = Dir
    Loop
    Do While i > 1
        i = i - 1
        FindDirectory StDir & DirList.Item(i), target
    Loop
    Set DirList = Nothing
End Sub
Private Sub Command1_Click()
    FindDirectory "c:", Text1.Text
    Label1.Caption = "Search End."
End Sub

上一个:VB API函数解析
下一个:VB如何开发控件

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,