如何计算多个压缩文件夹中的文件数?

时间:2017-12-18 18:21:26

标签: vba excel-vba excel

  

以下查询执行计算多个解压缩文件夹中的文件名的工作,但我想以这样的方式修改查询:它还包括压缩文件夹并计算这些文件夹中的文件名计数。

Sub count()

    Range("B2").Value = getFileCount("\\hhhhh\ttttttt\kkkkkk")
    Range("B3").Value = getFileCount("\\gggggg\xxxxxx\yyyyyyy")

    End Sub



    Function getFileCount(localRoot, Optional fld, Optional count As Long) As Long
        Dim fso, f, baseFolder, subFolder, ftpFile, i

        Set fso = CreateObject("Scripting.Filesystemobject")

        If IsMissing(fld) Then
            Set baseFolder = fso.GetFolder(localRoot)
        Else
            Set baseFolder = fld
        End If

        count = count + baseFolder.Files.count

        For Each subFolder In baseFolder.SubFolders
            getFileCount localRoot, subFolder, count
        Next

        getFileCount = count
    End Function
  

如果您有任何问题或意见,请与我们联系。

1 个答案:

答案 0 :(得分:0)

您只需要在文件扩展名为.zip时添加条件,它应将其视为文件夹并计算其中的项目。可以使用名为Shell的{​​{1}}函数来完成此操作,该函数获取字符串并将其更改为NameSpace对象。然后你可以使用你用来计算zip文件中的文件的相同技巧。请注意,zip文件本身将被计算,如果要排除它们,则必须修改计算zipfiles内容的代码块:

Folder