Find Count of Files in subfolders

Hi all

I have the following folder structure.

I would like to count the number of files in all the “Input” folders. Any idea how to do it fast? There can be situations like Child_2 folder where there are no files in its Input folder too.

In this scenario above, i would like to get a count of 3,as there is a total of 3 files in all the Input folders.

Thanks in advance!

Regards,
Jack

@robot_learner

Its easy…

Just use the following…

intCount = Directory.GetFiles(“Main Folder Path”).Count

for checking if the subfolder (Input Folder) exist, use the path exist activity which returns the boolean value.

Thanks and Regards,
@hacky

1 Like

Directory.GetFiles(Parent Folder,“*”, SearchOption.AllDirectories).Count

It counts only the files.

1 Like

@Priyanka_Ramesh there might be situations where there are files also in the “Logs” folder. I do not want them to be counted. Only want those files to be in “Input” folders to be counted. Thanksss

HI @robot_learner

To add to the solution given by @Priyanka_Ramesh, after you get the output of the code he provided, you can loop through the item list in the array, and check whether there are any files in the logs folder by checking the word “Logs” in each file path…

In the loop, get a count of files that reside in the logs folder based on the condition i mentioned, and subtract that from the total count :slight_smile:

3 Likes

(Directory.GetFiles(Parent Folder,“*”, SearchOption.AllDirectories).Count ) - (Directory.GetFiles(LogsFolder,“Logs *”, SearchOption.AllDirectories).Count)
Can you try like this, I’m not sure if it takes from All log folders.

3 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.