我这里有一个显示盘中所有目录的例程,你将它改改,既增加一个判断搜索就行了。显示盘中所有的目录
以下的代码把盘中所有的目录都显示在DriveListBox和一个Listbox中。需要一个 如果DirListBox隐藏的话,处理可以快一些。
Dim iLevel As Integer, iMaxSize As Integer
Dim i As Integer, j As Integer
ReDim iDirCount(22) As Integer
'最大 22 级目录
ReDim sdirs(22, 1) As String
'drive1 是 DriveListBox 控件
'dir1 是 DirListBox 控件
iLevel = 1
iDirCount(iLevel) = 1
iMaxSize = 1
sdirs(iLevel, iDirCount(iLevel)) = Left$(drive1.Drive, 2) & "\"
Do 
iLevel = iLevel + 1
iDirCount(iLevel) = 0
For j = 1 To iDirCount(iLevel - 1)
dir1.Path = sdirs(iLevel - 1, j)
dir1.Refresh
If iMaxSize < (iDirCount(iLevel) + dir1.ListCount) Then
ReDim Preserve sdirs(22, iMaxSize + dir1.ListCount + 1) As String
iMaxSize = dir1.ListCount + iDirCount(iLevel) + 1
End If
For i = 0 To dir1.ListCount - 1
iDirCount(iLevel) = _
iDirCount(iLevel) + 1 '子目录记数
sdirs(iLevel, iDirCount(iLevel)) = dir1.List(i)
Next i
Next j
'所有名称放到 List1 中
list1.Clear
If iDirCount(iLevel) = 0 Then
'如果无自目录
For i = 1 To iLevel
For j = 1 To iDirCount(i)
list1.AddItem sdirs(i, j)
Next j
Next i
Exit Do
End If
Loop

解决方案 »

  1.   

    dir(pathname,vbDirectory)即可,如果找到,该文件夹,返回路径名,否则,返回空
      

  2.   

    Private Sub Command1_Click()
        MsgBox ReportFolderStatus("C:\FindFolder")End Sub
    Function ReportFolderStatus(fldr)
      Dim fso, msg
      Set fso = CreateObject("Scripting.FileSystemObject")
      If (fso.FolderExists(fldr)) Then
        msg = fldr & " 存在。"
      Else
        msg = fldr & " 不存在。"
      End If
      ReportFolderStatus = msg
    End Function
      

  3.   

    Public Sub DeleteEverythingBelongToFolder(folderspec)
       '*****************************************
       '功能说明:显示目录(folderspec)下的所有文件及文件夹   On Error Resume Next
       
      '显示目录(folderspec)下的所有文件
        Dim fs, fc
        Dim f As Folder
        Set fs = CreateObject("Scripting.FileSystemObject")
        Set f = fs.GetFolder(folderspec)
           '显示文件夹
        Set SubSubFolders = f.SubFolders
        Dim TempFolder As Folder
        For Each TempFolder In SubSubFolders
             'add code here
        Next
           '显示文件
        Set tempFiles = f.Files
        Dim tempFile As File
        For Each tempFile In tempFiles
            'add code here
        Next
      
    End Sub
      

  4.   

    Public Sub DeleteEverythingBelongToFolder(folderspec)
       '*****************************************
       '功能说明:显示目录(folderspec)下的所有文件及文件夹   On Error Resume Next
       
      '显示目录(folderspec)下的所有文件
        Dim fs, fc
        Dim f As Folder
        Set fs = CreateObject("Scripting.FileSystemObject")
        Set f = fs.GetFolder(folderspec)
           '显示文件夹
        Set SubSubFolders = f.SubFolders
        Dim TempFolder As Folder
        For Each TempFolder In SubSubFolders
             'add code here
        Next
           '显示文件
        Set tempFiles = f.Files
        Dim tempFile As File
        For Each tempFile In tempFiles
            'add code here
        Next
      
    End Sub
      

  5.   

    同意 westwin(浪子西) 
    ================================================================
    [email protected]