2016-07-15 4 views
1

파일 이름과 해당 폴더를 a 및 b 열에 얻었습니다.각 폴더 및 하위 폴더에있는 파일 수를 개별적으로 표시합니다.

어떻게 각 폴더 및 하위 폴더의 파일 수를 계산할 수 있습니까? 계산 부분

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 
내가했던

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 

은 다음과 같다 :

은 참조입니다

어떻게 각 폴더 및 하위 폴더의 파일 수를 계산할 수 있습니까? 감사합니다

답변

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

번호를 개별적으로 표시하는 방법을 알고 계십니까? –

관련 문제