How to get the count of number of files and folders present in a main folder

Can any one help me how get count of number of files and folders present in a main folder and also the count of files inside sub folders along with name of subfolder


Use Directory.GetFiles(“FolderPath”).Count

gives you the output of the count of all files on the specific folder



But My Main Folder contains Sub Folders and individual Files…
and each sub folders inside main folder contains files…
1)It should count the no. of items in the main folder
2) It should check weather the first item is folder or file if its a folder it should click and count the items in subfolder.
3)it should come back and do it for all sub folders

You can also use a In-built Snippet for this



See this


@ Abhishek14No of files and (12.1 KB)
Give your folder path instead of test


Hey @Abhishek14

I want a one clarification from your side - as you mentioned

So you want All them in once like how many files count even including subfolders contain files or you want like Folder 1 contains 3 files then a subfolder of Folder 1 contains 2 files like so :slight_smile:

Let me know :slight_smile:


yes some what but it should iterate through the main folder and do it for all the sub folders in main folder
(in your case it is D:\samplek)

Hey @Abhishek14

IN my case SampleK is my root folder which is having 1 file and one sub folder having name Sample Folder which also contains 3 files and New Folder folder contains 2 files.


Yes suppose your root folder contains 5 folders and 10 files…
my question is how to iterate through all the 5 folders and give the count of each sub folder.
root contains (Folder 1,Folder 2, Folder 3,Folder 4, Folder 5, and File 1,File 2, File 3…File 10)
it should detect Folder and perform the actions accordingly and if its a file it should skip that item…

My Output Should contain count of
Root—5 Folders and 10 Files
Root/Folder 1---- 2 Folders and 10 Files
Root/Folder 2----
Root/Folder 3----
Root/Folder 4—
Root/Folder 5—

Hey @Abhishek14

So you want at root level count like below :slight_smile:



Please Can you help me with the work flow


Can you please share the xaml file or workflow for this.
I want the same which you have shown in your output in excel as i need to maintain the list in excel.
Please chare.

This is the one I am looking for. Please share the workflow along with the output in excel

Hi @kirti.iyer,

Can you please help me understand what do the syntax within the bracket mean?

Directory.GetDirectories(“test”, “", SearchOption.AllDirectories).Count()
Here I understand “test” is folder name
” is search pattern - meaning read all file types?
SearchOption.AllDirectories - Read sub folders too.

Please help me understand how this code works.