Count number of occurrences of a string from a list of strings

I have got a list of strings, they are filenames from a folder. Some filename contains same string of number with the others, and i am trying to count for each number in each file, how many files contain that same number.
Here’s a example of the filename:
image
In the list here, 47447 appeared twice, I would want an output of “2”
I currently have a For Each activity to go through each of the filename, they are stored in a variable and I have also extracted the number string from each filename with Regex, but i am having trouble to count the occurrence of each number string. I tried FilenameList.contains(NumberString), it only returns the True/False value, but i want a Int32 value with the number of occurrences.

Please help.

Thank you

Lazy way would be to extract the number from the file and count the results of Directory.GetFiles(ThisDirectory, "* " & number & ".pdf")
:slight_smile:

@siming
There are several techniques for this.

  • Create a list of keys (Unique IDs) eg. with the help of Regex
  • Iterate over the keys
  • search all filenames containing the key and count the occurence

grafik

Find a starte help here
siming.xaml (6.4 KB)

Kindly note it was a Quick done with a reduced set of simplified names. Please adopt to your needs

This works! and it’s so simple, i dont know why i didnt thought of it. Thank you so much!

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