我现在想知道我的一个文件夹下面有多少张图片,BMP和JPG格式的,做一个统计,怎么写代码呢?谢谢。

解决方案 »

  1.   

    Private Sub Command1_Click()
     Dim fso As New FileSystemObject
     Dim sName As String, sFile As String, sExt As String
     Dim sDirList() As String, iDirNum As Integer, I As Integer
     Dim FileName(52) As String * 20
        
     '首先枚举所有文件
     'sFile = Dir(sDirName + FileFilter, vbNormal + vbArchive + vbHidden)
     sFile = Dir("d:\job\*.*", vbNormal + vbArchive + vbHidden)
     I = 0
     Do While Len(sFile) > 0
        sFile = UCase(Trim(sFile))
        Print sFile
        I = I + 1
        FileName(I) = fso.GetFilename(sFile) '此处没进行过测试。
        sFile = Dir
     Loop
     '拷贝文件
     ProgressBar1.Visible = True
     ProgressBar1.Min = 0
     ProgressBar1.Max = I For j = 1 To I  ProgressBar1.Value = j  'fso.CopyFile FileName(j), aim_Folder
      fso.CopyFile "d:\job\" + FileName(j), "d:\11\"
      
     Next
     MsgBox "OK!"End Sub
      

  2.   

    最简单
    File1.Path = 文件路径
    File1.Pattern = "*.BMP"
    Debug.Print File1.ListCount
      

  3.   

    Private Sub command1_click()
         Dim j As Integer
         Dim fsol As New FileSystemObject
         Dim fil  As folder, n As File        
         Set fil = fsol.Getfolder("目标文件夹")     
          For Each n In fil.Files             
             j=j+1
          Next n
          MsgBox j                 
    End Sub