refactor to share directory searching code used by working set
increment i before comparing with array length
respond to code review
Merge pull request #5941 from adobe/randy/issue-5933-2

Refactor to share directory searching code used by working set