我现在需要实现以下功能:
用程序对某个文件夹下面的所以文件夹进行遍历,并得到这些文件夹的路径。
可在VB中该如何实现此功能呢。
希望大家能给如部分代码。越简单越好哦。
谢谢!

解决方案 »

  1.   

    private sub cmd_click()
    shell"explorer e:\",vbNormalFocus
    end sub
      

  2.   

    这是我写的一个遍历多层文件夹删除文件的例子
    你改改就可以用了Private Function LoopSearchFolder(FolderTemp As folder) As Integer
        Dim intLoopSearchFolder As Integer
        Dim FolderTempSave      As Folders
        Dim SubFolder           As folder
        Dim filetemp            As Files
        Dim FileItem            As File    Set filetemp = FolderTemp.Files
        For Each FileItem In filetemp
            If InStr(1, Trim(ComboxFileName), "*") <> 0 Then
                If FileItem.Name Like Trim(ComboxFileName) Then
                    FileItem.Delete (True)
                    mintExistFlg = 1
                End If
            Else
                If FileItem.Name = Trim(ComboxFileName) Then
                    FileItem.Delete (True)
                    mintExistFlg = 1
                End If
            End If
        Next    intLoopSearchFolder = FolderTemp.SubFolders.Count
        If intLoopSearchFolder <> 0 Then
            Set FolderTempSave = FolderTemp.SubFolders
            For Each SubFolder In FolderTempSave
                Call LoopSearchFolder(SubFolder)
            Next
        End If
    End Function
      

  3.   

    不行啊,VB中找不到 folder对象。
      

  4.   

    这是我写的一个遍历多层文件夹及文件的一个函数,你参考吧。Public Function File_Folder_List(ByVal source As String, Optional dFileList As Variant = Null, Optional dFolderList As Variant = Null) As Boolean
        '循环处理文件集合
        Dim fs, f, f1, d1, bFlag As Boolean
        On Error GoTo lError
        bFlag = True
        Set fs = CreateObject("Scripting.FileSystemObject")
        Set f = fs.GetFolder(source)    'fs 有 Files 和 SubFolders 集合
        
        '没有参数时,若要使 dFileList dFolderList 参与循环,将以下 If 语句封住即可
        If Not IsNull(dFileList) Then
            Set dFileList = f.Files
            For Each f1 In dFileList
                With f1
                    '处理集合中的文件
            
                    '
                End With
            Next f1
        End If    If Not IsNull(dFolderList) Then
            Set dFolderList = f.SubFolders
            For Each d1 In dFolderList
                With d1
                    '处理集合中的文件夹
            
                    '
                End With
            Next d1
        End If
        GoTo lExit
    lError:
        'MsgBox: vbCritical vbExclamation vbInformation vbQuestion
        MsgBox "文件夹 " & source & " 有误,请检查!", vbOKOnly + vbExclamation, "警告"
        bFlag = False
    lExit:
        If IsObject(f1) Then Set fd = Nothing
        If IsObject(d1) Then Set fc = Nothing
        If IsObject(f) Then Set f = Nothing
        If IsObject(fs) Then Set fs = Nothing
    End Function
      

  5.   

    运行“z_wenqian ”的代码时提示如下错误:实时错误 '-2147319779 (8002801d)':
    自动化错误
    对象库未注册
      

  6.   

    看这里比较详细
    http://blog.csdn.net/chenhui530/archive/2007/10/03/1810299.aspx
      

  7.   

    谢谢chenhui530(陈辉)
    这正是我想要的。