2016-07-15 6 views
1

ファイル名と対応するフォルダをカラム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 
カウント一部であります

どのように各フォルダとサブフォルダ内のファイル数を数えることができますか?ありがとう

答えて

0

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 
+0

おかげでトーマス、そのフォルダ内のファイルの合計数をカウントするための作品です。 しかし、フォルダとサブフォルダのファイル数を別々に表示したい場合はどうすればいいですか –

+0

私が助けることができてうれしいです。 –

+0

番号を個別に表示する方法は分かりますか? –

関連する問題