更简单的文件遍历方法

0 Reply , Posted in 程序代码 on 2017 28, 2017

Option Explicit
Private Sub Command1_Click()
    List1.Clear
    Dim obj As Object
    Dim Fpath As String
    For Each obj In Me
        If TypeOf obj Is CheckBox Then
            If obj.Value = 1 Then
                DoEvents
                ''''不知道为什么 Fpath = CStr(Left(obj.Caption, 1) & ":\") 这里不加斜杠就不能正确遍历C盘
                If CStr(Left(obj.Caption, 1)) = "C" Then
                     Fpath = CStr(Left(obj.Caption, 1) & ":\")
                Else
                     Fpath = CStr(Left(obj.Caption, 1) & ":")
                End If
                ShowFolderList (Fpath)
            End If
        End If
    Next
End Sub
Sub ShowFolderList(folderspec As String)
 On Error Resume Next
    Dim fs, f, f1, fc, s
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set f = fs.GetFolder(folderspec)
    Set fc = f.Files
    For Each f1 In fc
         DoEvents
         List1.AddItem folderspec & "\" & f1.Name
    Next
    Set fc = f.SubFolders
    For Each f1 In fc
       DoEvents
       ShowFolderList (folderspec & "\" & f1.Name)
    Next
End Sub

标签:    

相关推荐

vb读取access并且显示  (2017-5-11 9:18:27)

VB 获取CPU温度示例  (2017-5-8 10:35:11)

VB程序逆向反汇编常见的函数   (2017-5-8 10:32:0)

VB内嵌汇编的模块示例  (2017-5-8 10:24:4)

内存数据的读写(PC)   (2017-3-1 17:51:40)

用VB制作外挂   (2017-3-1 16:16:53)

发表评论:



◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

                       

  鄂公网安备 42112502000156号     鄂ICP备16019550号