Dim hFile As Long
Dim WFD As WIN32_FIND_DATA
    hFile = FindFirstFile("c:\*.*", WFD)
    If hFile <> INVALID_HANDLE_VALUE Then
        
        Do            DoEvents
           
    
        List1.AddItem "c:\" & Left$(WFD.cFileName, InStr(WFD.cFileName, vbNullChar) - 1)
        
        
        Loop While FindNextFile(hFile, WFD)
        
    
        Call FindClose(hFile)
    
    End If
请问这样怎么扫描子文件夹? 能否给修改下。。

解决方案 »

  1.   

    Public Function ff(ByVal np As String) As Long
        Dim fh as long
        Dim ret As Long
        Dim s As String
        Dim tp As String
        Dim t as WIN32_FIND_DATA    tp = np & "\*.*"
        fh = FindFirstFile(tp, t)
        If fh = -1 Then
            ff = 0
            Exit Function
        End If
        Do
            DoEvents
            If Left(t.cFileName, 1) <> "." Then
                t.cFileName = ""
                ret = FindNextFile(fh, t)
                If ret = 0 Then Exit Function
                If Left(t.cFileName, 1) <> "." Then
                    'put your own code here
                     p = np & "\" & Left(t.cFileName, InStr(t.cFileName, Chr(0)) - 1)
                     ff (p)
                End If
            End If
            t.cFileName = ""
        
        Loop Until fh = -1End Function
    你肿么连个递归都没有
      

  2.   

    吃空格Public Function ff(ByVal np As String) As Long'np为搜索路径
      
      Dim fh As Long
      Dim ret As Long
      Dim p As String
      Dim tp As String
      Dim t As WIN32_FIND_DATA  tp = np & "\*.*"
      fh = FindFirstFile(tp, t)
      If fh = -1 Then
        ff = 0
        Exit Function
      End If
      Do
        DoEvents
        If Left(t.cFileName, 1) <> "." Then
            t.cFileName = ""
            ret = FindNextFile(fh, t)
            If ret = 0 Then Exit Function
            If Left(t.cFileName, 1) <> "." Then
                
                'Debug.Print t.cFileName
                'put your own code       
     
                p = np & "\" & Left(t.cFileName, InStr(t.cFileName, Chr(0)) - 1)
                ff (p)
            End If
        End If
        t.cFileName = ""
        
      Loop Until fh = -1End Function
      

  3.   

    MSN里面有个现成的函数dir(),自己去查吧,好几年没写VB代码了
      

  4.   

    shell "cmd /c dir /a-d /b /s c:\*.* >d:\allfilesinc.txt",vbHide
    '然后读文件d:\allfilesinc.txt的内容