如何统计某个目录及子目录下后缀为*.exe的文件数?

解决方案 »

  1.   

        Dim fPath As String, sName As String, n As Integer
        
        fPath = "c:\"
        sName = Dir(fPath & "*.txt")
        
        Do Until sName = ""
        n = n + 1
        sName = Dir()
        Loop
        
        Debug.Print n
      

  2.   

    Dim n As LongPrivate Sub Command1_Click()
        Call a("E:\")
        Debug.Print n
    End SubSub a(sDir As String)
        Dim fs, ds, d, f
        Set fs = CreateObject("Scripting.FileSystemObject")
        Set ds = fs.getfolder(sDir)
        For Each f In ds.Files
            If UCase(Right(f.Shortname, 3)) = "EXE" Then n = n + 1
        Next f
        For Each d In ds.SubFolders
            a d.Path
        Next d
    End Sub
      

  3.   

    去Dos下,运行"dir /s /b *.exe >file.txt",统计file.txt行数,这样运行最快。文件名和路径名全有了。