计算每个文件夹和子文件夹中的文件数量,然后分别显示 [英] count how many of files in each folder and subfolder then display separately

查看:253
本文介绍了计算每个文件夹和子文件夹中的文件数量,然后分别显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



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



这些是引用: / p>

在特定文件夹中计数文件,并将数字显示为1个cel



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



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

  Private Sub SelectFolder_Click()
调用GetAllFolders(x,strPath,objFso,intCountRows)
调用计数
End Sub

以下是计数部分

  Sub count()
Dim FolderPath As String,path As String,count As Integer
Dim Filena我as String
Dim strPath As String

FolderPath =D:\Users\Desktop\test

文件名= Dir()

尽管文件名<>
count = count + 1
文件名= Dir()
循环

范围(C3)。Value = count
'MsgBox count &安培; :文件夹中的文件
End Sub

我如何计算文件数在每个文件夹和子文件夹?谢谢

解决方案

GetFileCount将计算目录和目录子目录中的所有文件。



Range(C3)。Value = getFileCount(D:\Users\Desktop\test)

 函数getFileCount(localRoot,可选fld,可选count as Long)As Long 
Dim fso,f,baseFolder,subFolder,ftpFile,i

设置fso = CreateObject(Scripting.Filesystemobject)

如果IsMissing(fld)然后
设置baseFolder = fso.GetFolder(localRoot)
Else
Set baseFolder = fld
End If

count = count + baseFolder.Files.count

对于每个子文件夹在baseFolder.SubFolders
getFileCount localRoot,subFolder,count
下一个

getFileCount = count
结束函数


I have obtained the filename and corresponding folder in column a and b.

How Can I count the number of files in each folder and subfolder?

these are the references:

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/

I have done the following so far

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

The following is the counting part

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

How Can I count the number of files in each folder and subfolder? Thanks

解决方案

GetFileCount will count all the files in a directory and the directory's sub-directories.

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

这篇关于计算每个文件夹和子文件夹中的文件数量,然后分别显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆