gpt4 book ai didi

excel - 计算每个文件夹和子文件夹中有多少文件然后分别显示

转载 作者:行者123 更新时间:2023-12-04 21:59:08 25 4
gpt4 key购买 nike

我在 a 和 b 列中获得了文件名和相应的文件夹。

如何计算每个文件夹和子文件夹中的文件数?

这些是引用:

count files in specific folder and display the number into 1 cel

http://software-solutions-online.com/excel-vba-find-and-list-all-files-in-a-directory-and-its-subdirectories/

到目前为止,我已经完成了以下操作

Private Sub SelectFolder_Click()
Call GetAllFolders(x, strPath, objFso, intCountRows)
Call count
End Sub

以下是计数部分
Sub count()
Dim FolderPath As String, path As String, count As Integer
Dim Filename As String
Dim strPath As String

FolderPath = "D:\Users\Desktop\test"

Filename = Dir("")

Do While Filename <> ""
count = count + 1
Filename = Dir()
Loop

Range("C3").Value = count
'MsgBox count & " : files found in folder"
End Sub

如何计算每个文件夹和子文件夹中的文件数?谢谢

最佳答案

GetFileCount 将计算一个目录和该目录的子目录中的所有文件。
Range("C3").Value = getFileCount("D:\Users\Desktop\test")

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

关于excel - 计算每个文件夹和子文件夹中有多少文件然后分别显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38391938/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com