Refactor to share directory searching code used by working set

This does refactoring described in https://github.com/adobe/brackets/issues/5651 to fix #5933.