Fix bug that caused directories to be counted multiple times during recursion