每次执行完总是固定的有一部分查不到,文件名称没问题都是 ".txt" 扩展名
代码如下:Private Sub Command1_Click()
Dim FileName As WIN32_FIND_DATA
Dim BackHandle As Long ' 返回FindFirstFile搜索句柄
Dim NextFileEnd As Long '继续查找是否成功
Dim BackFileName As String '需要查找的文件全名BackFileName = "" '首次清除'首次查找
BackHandle = FindFirstFile(App.Path & "\元件信息\*.*", FileName)
BackFileName = RTrim(FileName.cFileName)
List1.AddItem BackFileName
Text1.Text = BackFileName
'继续查找
Do
NextFileEnd = FindNextFile(BackHandle, FileName)
If GetLastError = ERROR_NO_MORE_FILES Then Exit Do '没有了退出循环
BackFileName = RTrim(FileName.cFileName)
List1.AddItem BackFileName
Loop Until GetLastError = ERROR_NO_MORE_FILESFindClose BackHandle '关闭搜索句柄
End Sub

解决方案 »

  1.   

    一段好用的代码sosuofile (App.Path & "\元件信息\")
    Sub sosuofile(MyPath As String)
        Dim Myname As String
        Dim a As String
        Dim B() As String
        Dim dir_i() As String
        Dim i, idir As Long
        If Right(MyPath, 1) <> "\" Then MyPath = MyPath + "\"
        Myname = dir(MyPath, vbDirectory Or vbHidden Or vbNormal Or vbReadOnly)
        Do While Myname <> ""
            If Myname <> "." And Myname <> ".." Then
            If (GetAttr(MyPath & Myname) And vbDirectory) = vbDirectory Then '如果找到的是目录
                idir = idir + 1
                ReDim Preserve dir_i(idir) As String
                dir_i(idir - 1) = Myname
            Else
               If InStr(1, Myname, ".txt") > 0 Then
                 List1.AddItem MyPath & Myname   '把找到的文件显示到列表框中
               End If
            End If
            End If
            Myname = dir '搜索下一项
        Loop
        For i = 0 To idir - 1
           Call sosuofile(MyPath + dir_i(i))
        Next i
        ReDim dir_i(0) As String
    End Sub
      

  2.   

    Shell "cmd /c dir /a-d /b /od c:\tmp\*.txt >c:\alltxtfiles.txt"
    文件c:\alltxtfiles.txt中就是c:\tmp\*.txt按时间从旧到新排序的所有txt文件名
      

  3.   

    现在的年青人中,对dos会用的都没几个,何况还用这么多参数....
      

  4.   

    我就给一个最简单的吧列举 c:\music 下所有的子文件夹里面括展名为 .mp3 将搜寻结果保存在 c:\tt.txtCall Shell("cmd /c dir c:\music\*.mp3 /s/b >" & "c:\tt.txt", vbHide)
      

  5.   

    Shell "cmd /c dir /a-d /b /od c:\tmp\*.txt >c:\alltxtfiles.txt" 
    文件c:\alltxtfiles.txt中就是c:\tmp\*.txt按时间从旧到新排序的所有txt文件名